Skip to content

Instantly share code, notes, and snippets.

@soulcutter
Created April 9, 2013 14:42
Show Gist options
  • Save soulcutter/5346232 to your computer and use it in GitHub Desktop.
Save soulcutter/5346232 to your computer and use it in GitHub Desktop.
Why we need to dup things in define_method blocks
class Obj
def self.new_method(name, options = {})
define_method(name) { options }
end
end
o = Obj.new
options = { one: :two }
Obj.new_method('baz', options)
o.baz # =>{:one=>:two}
options[:asgfasdgsadg] = :sdagsadg
o.baz # => {:one=>:two, :asgfasdgsadg=>:sdagsadg}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment