Skip to content

Instantly share code, notes, and snippets.

@jordelver
Last active December 20, 2015 06:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordelver/6087563 to your computer and use it in GitHub Desktop.
Save jordelver/6087563 to your computer and use it in GitHub Desktop.
class Foo
def bar(arg)
arg.call
end
end
class X
def call
"Normal class"
end
end
Y = Class.new do
def call
"Class using Class.new"
end
end
Z = Proc.new do
"Proc!"
end
class MethodObject
def foo
"No call defined!"
end
end
puts Foo.new.bar(X.new)
"Normal class"
puts Foo.new.bar(Y.new)
"Class using Class.new"
puts Foo.new.bar(Z)
"Proc!"
puts Foo.new.bar(lambda { "Lambda!" })
"Lambda!"
puts Foo.new.bar(-> { "Stabby lambda!" })
"Stabby lambda!"
puts Foo.new.bar(MethodObject.new.method(:foo))
"No call defined!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment