Last active
May 6, 2019 09:11
-
-
Save hanachin/2060751fca3444922386879ac666541e to your computer and use it in GitHub Desktop.
Ruby 2.7の新機能メソッド参照演算子 ref: https://qiita.com/hanachin_/items/1aa1ba38a87dee91aed6
This file contains hidden or 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
123.method(:to_s) | |
# => #<Method: Integer#to_s> |
This file contains hidden or 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
meth = 123.method(:to_s) | |
# => #<Method: Integer#to_s> | |
meth.call | |
# => "123" | |
meth.call(16) | |
# => "7b" |
This file contains hidden or 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
123.:to_s | |
# => #<Method: Integer#to_s> |
This file contains hidden or 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 Object | |
def method(*) | |
nil | |
end | |
end | |
123.method(:to_s) | |
# => nil | |
123.:to_s.call | |
# => "123" |
This file contains hidden or 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
using Module.new { | |
refine(Object) do | |
def method(*); end | |
end | |
} | |
method(:puts) | |
# => nil | |
self.:puts | |
# => #<Method: main.puts> |
This file contains hidden or 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
using Module.new { | |
refine(Object) do | |
def method(*); end | |
end | |
} | |
self.:method.call(:puts).call(1) | |
# 1 |
This file contains hidden or 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
1.method(:-@).call | |
# => -1 | |
1.:[email protected] | |
# => -1 |
This file contains hidden or 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
[1,2,3].map(&2.:*) | |
# => [2, 4, 6] | |
["エロ"].any?(&"イエロー".:include?) | |
# => true | |
require "prime" | |
(1..10).select(&Prime.:prime?) | |
# => [2, 3, 5, 7] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment