Skip to content

Instantly share code, notes, and snippets.

@jquave
Created August 12, 2016 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquave/39e4c5fb1f060d2a9bcf35020878bbe7 to your computer and use it in GitHub Desktop.
Save jquave/39e4c5fb1f060d2a9bcf35020878bbe7 to your computer and use it in GitHub Desktop.
# Framework Object::say_hello
class Object
def say_hello
"hello"
end
end
# Your Object class
class Object
module InSpanish
def say_hello
"hola"
end
end
include InSpanish
module InEnglish
expects_method = Object.instance_method(:say_hello)
define_method :say_hello do |*args|
expects_method.bind(self).call(*args)
end
end
include InEnglish
def say_hello
(@language || InEnglish).instance_method(:say_hello).bind(self).call
end
def in_english(&block)
@language = InEnglish
instance_eval(&block)
end
def in_spanish(&block)
@language = InSpanish
instance_eval(&block)
end
end
in_english do
say_hello # => "hello"
end
in_spanish do
say_hello # => "hola"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment