Module: CanSelfDoIt::Auto

Defined in:
lib/can_self_do_it/auto.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object

Automatic method generation. Everything defined as /can_.+?/ that does not exists get name from param type i.e methods like can_do_something?(project) => can_do_something_project



8
9
10
11
12
13
14
15
16
17
# File 'lib/can_self_do_it/auto.rb', line 8

def method_missing(symbol, *args, &block)
  if can_self_do_it_method?(symbol)
    raise ArgumentError, "wrong number of arguments(#{args.size}1 for 1)"  unless args.size == 1
    obj = args[0]
    new_symbol = "#{symbol.to_s[0..-2]}_#{CanSelfDoIt::Helper.class_2_method_sub_str(obj.class)}?".to_sym
    self.public_methods.include?(new_symbol) ? send(new_symbol, obj) : can_modify_default?(obj)
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(symbol, include_all) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/can_self_do_it/auto.rb', line 19

def respond_to_missing?(symbol, include_all)
  can_self_do_it_method?(symbol) || super
end