Module: Argible::ClassMethods
- Defined in:
- lib/argible.rb
Instance Method Summary collapse
-
#argible(options = {}) ⇒ Object
Used to annotate methods that should have their argument values automatically resolved.
-
#method_added(method_name) ⇒ Object
This callback is used by Argible to determine which methods have been annotated with the argible() method.
Instance Method Details
#argible(options = {}) ⇒ Object
Used to annotate methods that should have their argument values automatically resolved
argible
def annotated_method(foo, bar)
...
end
The options
Hash passed in can define custom processing to occur on a per argument basis. For example:
argible(
:one => :to_i, # call method 'to_i' on the argument value
:two => lambda{ |value| return value }, # defines a Proc to run (resolved argumnet value passed to Proc)
:three => method(:meth_name), # method to call (resolved argumnet value passed to Method)
:four => :@four # argument value is set to the instance variable of name (i.e. @four)
)
30 31 32 |
# File 'lib/argible.rb', line 30 def argible( = {}) @method_definition = MethodDefinition.new() end |
#method_added(method_name) ⇒ Object
This callback is used by Argible to determine which methods have been annotated with the argible() method.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/argible.rb', line 35 def method_added(method_name) unless @method_definition.nil? @method_definition.name = method_name @method_definition.arguments = get_arguments(method_name) # Add class instance variable 'argible_methods' if it does not already exist unless self.respond_to?(:argible_methods) class << self; attr_accessor :argible_methods; end self.instance_variable_set(:@argible_methods, Hash.new) end self.argible_methods[method_name] = @method_definition @method_definition = nil # clearing to prevent infinite loop build_alias_method(method_name) end end |