Class: Class

Inherits:
Object show all
Defined in:
lib/around.rb

Instance Method Summary collapse

Instance Method Details

#around_disable_feature(feature_name) ⇒ Object



36
37
38
39
# File 'lib/around.rb', line 36

def around_disable_feature feature_name
  rx = /^(.+)_without_#{feature_name}([?!])?$/
  instance_methods.select { |m| m =~ rx }.each { |m| alias_method m.to_s.sub(rx, '\\1\\2'), m }
end

#def_around(method_name, feature_name, &method_definition) ⇒ Object

Like ActiveSupport’s alias_method_chain but with Even Less Typing™



19
20
21
22
23
24
25
26
27
# File 'lib/around.rb', line 19

def def_around method_name, feature_name, &method_definition
  method_name_prefix  = method_name.to_s.sub(/[!?]$/, '')
  method_name_punct   = $&
  method_name_without = [method_name_prefix, '_without_', feature_name, method_name_punct].join
  method_name_with    = [method_name_prefix, '_with_',    feature_name, method_name_punct].join
  define_method method_name_with, &method_definition
  alias_method method_name_without, method_name unless method_defined? method_name_without
  alias_method method_name, method_name_with
end