GetArgs

Used in mapping controller arguments to the params hash. NOTE: You must have the ‘ruby2ruby’ gem installed for this to work.

Examples

  # In PostsController
  def show(id)  #=> id is the same as params[:id]

Constants

Methods

Public Instance Methods

build_args(args_node) click to toggle source
    # File lib/merb-action-args/jruby_args.rb, line 25
25:   def build_args(args_node)
26:     args = []
27:     required = []
28:     optional = []
29: 
30:     # required args
31:     if (args_node.args && args_node.args.size > 0)
32:       required = args_node.args.child_nodes.map { |arg| [arg.name.to_s.intern] }
33:     end
34:   
35:     # optional args
36:     if (args_node.opt_args && args_node.opt_args.size > 0)
37:       optional = args_node.opt_args.child_nodes.map do |arg|
38:         name = arg.name.to_s.intern
39:         value_node = arg.value_node
40:         case value_node
41:         when org.jruby.ast::FixnumNode
42:           value = value_node.value
43:         when org.jruby.ast::SymbolNode
44:           value = value_node.get_symbol(JRuby.runtime)
45:         when org.jruby.ast::StrNode
46:           value = value_node.value
47:         else
48:           value = nil
49:         end
50:         [name, value]
51:       end
52:     end
53: 
54:     args = required + optional
55:     return [args, optional.map{|name,| name}]
56:   end
get_args() click to toggle source
    # File lib/merb-action-args/jruby_args.rb, line 7
 7:   def get_args
 8:     real_method = JRuby.reference(self)
 9: 
10:     # hack to expose a protected field; could be improved in 1.1.5
11:     method_field = org.jruby.RubyMethod.java_class.declared_field(:method)
12: 
13:     method_field.accessible = true
14:   
15:     dyn_method = method_field.value(real_method)
16: 
17:     case dyn_method
18:     when Methods.MethodArgs
19:       return build_args(dyn_method.args_node)
20:     else
21:       raise "Can't get args from method: #{self}"
22:     end
23:   end
get_args() click to toggle source
    # File lib/merb-action-args/vm_args.rb, line 8
 8:   def get_args
 9:     unless respond_to?(:parameters)
10:       raise NotImplementedError, "Ruby #{RUBY_VERSION} doesn't support #{self.class}#parameters"
11:     end
12: 
13:     required = []
14:     optional = []
15: 
16:     parameters.each do |(type, name)|
17:       if type == :opt
18:         required << [name, nil]
19:         optional << name
20:       else
21:         required << [name]
22:       end
23:     end
24: 
25:     return [required, optional]
26:   end
get_args() click to toggle source

Returns

Array

Method arguments and their default values.

Examples

  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
82:   def get_args
83:     klass, meth = self.to_s.split(/ /).to_a[1][0..2].split("#")
84:     # Remove stupidity for #<Method: Class(Object)#foo>
85:     klass = $` if klass =~ /\(/
86:     ParseTreeArray.translate(Object.full_const_get(klass), meth).get_args
87:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.