-
-
Save AlexWayfer/c175f338b5c3812f0d7222b2ffcfa417 to your computer and use it in GitHub Desktop.
Opal Singleton method in Instance method
This file contains 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 App | |
def init_obj | |
@obj = Object.new | |
@obj.define_singleton_method :foo do |arg| | |
p 'singleton foo' | |
return if arg == 1 | |
puts 'bar' | |
end | |
end | |
def run_obj | |
@obj.foo(0) | |
@obj.foo(1) | |
end | |
end | |
app = App.new | |
app.init_obj | |
app.run_obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment