Based on the JavaScript background, I'm used to being able to use the dynamic JavaScript region to encapsulate values โโin a function. For instance:
function Dog( firstname, lastname ) { this.fullname = firstname + lastname return { say_name: function () { return fullname; } } }
Now in Ruby, I'm not sure that something like this will work too well:
class Foo attr_accessor :bar, :baz def initialize bar, baz @bar = bar @baz = baz end def give_me_a_proc return Proc.new { @bar + @baz } end end
Can someone give a brief explanation of how scope works in Ruby? If I call Proc returned from give_me_a_proc , will it still have access to its time domain?
Also, are the values โโfixed after I define proc or will any changes made to Foo be transferred to Proc even after they are determined?
source share