def my_method(*args)
options = args.extract_options!
puts "Arguments: #{args.inspect}"
puts "Options: #{options.inspect}"
end
my_method(1, 2)
# Arguments: [1, 2]
# Options: {}
my_method(1, 2, :a => :b)
# Arguments: [1, 2]
# Options: {:a=>:b}
2014年4月18日 星期五
[Ruby on rails ] use args.extract_options!
神奇的 args.extract_options!
【下列文章您可能也有興趣】
>>>Ruby on Rails
- [Rails Error] rubygems/core_ext/kernel_require.rb in `require': cannot load such file -- bundler/setup (LoadError)
- [Rails] 運用 Net::HTTP and URI
- [Rails] require: cannot load such file -- bundler/setup (LoadError)
- Ruby &block lambda proc yield 使用
- [Rails] ActiveRecord::Enum
- Rails 4 class method 使用 alias_attribute, alias_method_chain, delegate, mattr_accessor
- An ActionDispatch::RemoteIp::IpSpoofAttackError 10.xx.xx.xx
- Rails 3.2.20 redirecting class 內的 _compute_redirect_to_location
- Devise Issue: “[17] is not a symbol” [duplicate]
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言