Skip to content

Instantly share code, notes, and snippets.

@AlexWayfer
Last active December 11, 2016 21:45
Show Gist options
  • Save AlexWayfer/c175f338b5c3812f0d7222b2ffcfa417 to your computer and use it in GitHub Desktop.
Save AlexWayfer/c175f338b5c3812f0d7222b2ffcfa417 to your computer and use it in GitHub Desktop.
Opal Singleton method in Instance method
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