Skip to content

Instantly share code, notes, and snippets.

@mrk21
Created January 22, 2020 05:08
Show Gist options
  • Save mrk21/3770a40318a867405073b7f3dc56e0d5 to your computer and use it in GitHub Desktop.
Save mrk21/3770a40318a867405073b7f3dc56e0d5 to your computer and use it in GitHub Desktop.
Local variables accessible singleton method definition for Ruby
class Hoge
def a
1
end
end
hoge = Hoge.new
b = 2
hoge.define_singleton_method(:b){ b }
puts hoge.a #=> 1
puts hoge.b #=> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment