Created
January 22, 2020 05:08
-
-
Save mrk21/3770a40318a867405073b7f3dc56e0d5 to your computer and use it in GitHub Desktop.
Local variables accessible singleton method definition for Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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