Used in mapping controller arguments to the params hash. NOTE: You must have the ‘ruby2ruby’ gem installed for this to work.
# In PostsController def show(id) #=> id is the same as params[:id]
# File lib/merb-action-args/jruby_args.rb, line 25 def build_args(args_node) args = [] required = [] optional = [] # required args if (args_node.args && args_node.args.size > 0) required = args_node.args.child_nodes.map { |arg| [arg.name.to_s.intern] } end # optional args if (args_node.opt_args && args_node.opt_args.size > 0) optional = args_node.opt_args.child_nodes.map do |arg| name = arg.name.to_s.intern value_node = arg.value_node case value_node when org.jruby.ast::FixnumNode value = value_node.value when org.jruby.ast::SymbolNode value = value_node.get_symbol(JRuby.runtime) when org.jruby.ast::StrNode value = value_node.value else value = nil end [name, value] end end args = required + optional return [args, optional.map{|name,| name}] end
Array |
Method arguments and their default values. |
class Example def hello(one,two="two",three) end def goodbye end end Example.instance_method(:hello).get_args #=> [[:one], [:two, "two"], [:three, "three"]] Example.instance_method(:goodbye).get_args #=> nil
# File lib/merb-action-args/mri_args.rb, line 82 def get_args klass, meth = self.to_s.split(/ /).to_a[1][0..-2].split("#") # Remove stupidity for #<Method: Class(Object)#foo> klass = $` if klass =~ /\(/ ParseTreeArray.translate(Object.full_const_get(klass), meth).get_args end
Generated with the Darkfish Rdoc Generator 2.