Module: NegativeMethod

Defined in:
lib/negative_method.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(negative_method_name, *args) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/negative_method.rb', line 3

def method_missing(negative_method_name, *args)

  positive_method = get_positive_method_from negative_method_name.to_s
  if ( positive_method && self.respond_to?(positive_method) )
      return !self.send(positive_method, *args)
  end

  _method_missing negative_method_name, *args
end

Instance Method Details

#_method_missingObject



2
# File 'lib/negative_method.rb', line 2

alias :_method_missing :method_missing

#get_positive_method_from(method_name) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/negative_method.rb', line 13

def get_positive_method_from method_name
  if method_name.match(/^no_/)
    return method_name.sub(/no_/,'')
  elsif method_name.match(/^not_/) || method_name.match(/_not_/)
    return method_name.sub(/not_/,'')
  elsif method_name.match(/_not$/) || method_name.match(/_not?/)
    return method_name.sub(/_not/,'')
  end
end