So that a function takes care about setting the 42 and another for caring about changing the value of z to 100?
thanks in advance
sala
Let’s try again…
There’s Observable:
~$ ri Observable
------------------------------------------------------ Class: Observable
Implements the Observable design pattern as a mixin so that other
objects can be notified of changes in state. See observer.rb for
details and an example.
I don’t think that there exists some method for this purpose. You can
use Ruby’s trace possibilities or a simple method for looking at local
variables at special points…
def show_local_vars(bind, *d)
puts ‘----- variables -----’
vars = eval(“local_variables”, bind)
(d.length == 0 ? vars : (d.map{|s|s.to_s} & vars)).each do |v|
begin
puts “#{v}=#{eval(v,bind)}”
rescue
puts “+++++ Variable ‘#{v}’ not defined”
end
end
end
def x()
z = 10
show_local_vars(binding)
z = 42
show_local_vars(binding, :z, :a)
end
I don’t think that there exists some method for this purpose. You can
use Ruby’s trace possibilities or a simple method for looking at local
variables at special points…
What methods does ruby itself [so, the C-core] uses to initialize a
variable
(local, global, instance, whatever)?
And what method(s) is(are) used to give an exisiting variable a new
value?
thanks
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.