Skip to content

Instantly share code, notes, and snippets.

@stevencch99
Created May 11, 2019 13:07
Show Gist options
  • Save stevencch99/e25763cc3686ac9adb72434d900f6188 to your computer and use it in GitHub Desktop.
Save stevencch99/e25763cc3686ac9adb72434d900f6188 to your computer and use it in GitHub Desktop.
class Greeter
attr_reader :greeting
def initialize(greeting)
@greeting = greeting
end
def greet(subject)
"#{greeting}, #{subject}!"
end
end
greeter = Greeter.new("Hello")
greet = greeter.method(:greet)
# 也一樣可以透過呼叫 Proc 的方法使用它:
p greet.call("world") # => "Hello, world!"
p greet.("world") # => "Hello, world!"
p greet["world"] # => "Hello, world!"
p greet === "world" # => "Hello, world!"
@stevencch99
Copy link
Author

Could you be more specific?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment