Skip to content

Instantly share code, notes, and snippets.

@iyuuya
Last active August 29, 2015 14:26
Show Gist options
  • Save iyuuya/dc1bdbd19a0c946bfc26 to your computer and use it in GitHub Desktop.
Save iyuuya/dc1bdbd19a0c946bfc26 to your computer and use it in GitHub Desktop.
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
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)
[]
=> []
@iyuuya
Copy link
Author

iyuuya commented Jul 31, 2015

A継承させるの忘れた

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