Both splat and keyword args in Ruby 1.9 -
Both splat and keyword args in Ruby 1.9 -
i have method in ruby 2.0 script next signature:
def method(*args, **kwargs) this script fails run in ruby 1.9 because ** syntax new. there way alter method signature while preserving ruby 2.0 behavior? ideally, not modify callers.
note there methods in ruby core in 1.9 take both variable number of arguments , additional options, e.g., kernel#system.
pretty close same behavior, although you'll have access kwargs via keys:
def method(*args) kwargs = case args.last when hash args.pop else {} end # stuff here # puts args # puts kwargs end ruby
Comments
Post a Comment