Last active
August 29, 2015 14:26
-
-
Save iyuuya/dc1bdbd19a0c946bfc26 to your computer and use it in GitHub Desktop.
This file contains 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 A; end | |
class B | |
def hoge | |
# do something | |
end | |
end | |
class C | |
def hoge(*vals) | |
# do something | |
end | |
end | |
class D | |
attr_accessor :v | |
def fuga(val=nil) | |
v.try(:xx) || v.hoge(*val) | |
end | |
end | |
b = B.new | |
c = C.new | |
d = D.new | |
d.v = b | |
d.fuga(1) | |
d.v = c | |
d.fuga |
This file contains 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
2.2.2 [1] pry(main)> def hoge; :hoge; end | |
=> :hoge | |
2.2.2 [2] pry(main)> v = nil | |
=> nil | |
2.2.2 [3] pry(main)> hoge(*v) | |
=> :hoge | |
2.2.2 [4] pry(main)> (*v) | |
SyntaxError: unexpected '\n', expecting '=' | |
2.2.2 [4] pry(main)> [*v] | |
=> [] | |
2.2.2 [5] pry(main)> def hoge(a) | |
2.2.2 [5] pry(main)* p a | |
2.2.2 [5] pry(main)* end | |
=> :hoge | |
2.2.2 [6] pry(main)> hoge(*nil) | |
ArgumentError: wrong number of arguments (0 for 1) | |
from (pry):5:in `hoge' | |
2.2.2 [7] pry(main)> def hoge(*a) | |
2.2.2 [7] pry(main)* p a | |
2.2.2 [7] pry(main)* end | |
=> :hoge | |
2.2.2 [8] pry(main)> hoge(*nil) | |
[] | |
=> [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A継承させるの忘れた