Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Introspection/Ruby/introspection-1.rb
Normal file
2
Task/Introspection/Ruby/introspection-1.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
exit if RUBY_VERSION < '1.8.6'
|
||||
puts bloop.abs if defined?(bloop) and bloop.respond_to?(:abs)
|
||||
23
Task/Introspection/Ruby/introspection-2.rb
Normal file
23
Task/Introspection/Ruby/introspection-2.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
def variable_counter(b)
|
||||
int_vars = []
|
||||
sum = 0
|
||||
check_var = lambda do |name, value|
|
||||
if value.is_a?(Integer)
|
||||
int_vars << name
|
||||
sum += value
|
||||
end
|
||||
end
|
||||
|
||||
global_variables.each {|varname| check_var.call(varname, eval(varname.to_s))}
|
||||
eval('local_variables', b).each {|varname| check_var.call(varname, eval(varname.to_s, b))}
|
||||
|
||||
puts "these #{int_vars.length} variables in the global scope are integers:"
|
||||
puts int_vars.inspect
|
||||
puts "their sum is: #{sum}"
|
||||
end
|
||||
|
||||
an_int = 5
|
||||
a_string = 'foo'
|
||||
a_float = 3.14
|
||||
|
||||
variable_counter(binding)
|
||||
Loading…
Add table
Add a link
Reference in a new issue