Module: Rlyeh::Utils
- Defined in:
- lib/rlyeh/utils.rb
Class Method Summary collapse
- .extract_options(args) ⇒ Object
- .extract_options!(args) ⇒ Object
- .generate_method(obj, name, method = nil, &block) ⇒ Object
- .singleton_class(obj) ⇒ Object
Class Method Details
.extract_options(args) ⇒ Object
14 15 16 |
# File 'lib/rlyeh/utils.rb', line 14 def (args) args.last.is_a?(::Hash) ? args.last : {} end |
.extract_options!(args) ⇒ Object
18 19 20 |
# File 'lib/rlyeh/utils.rb', line 18 def (args) args.last.is_a?(::Hash) ? args.pop : {} end |
.generate_method(obj, name, method = nil, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rlyeh/utils.rb', line 22 def generate_method(obj, name, method = nil, &block) name = name.to_s method ||= block obj.instance_eval do define_method name, &method method = instance_method name remove_method name method end end |
.singleton_class(obj) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/rlyeh/utils.rb', line 4 def singleton_class(obj) if obj.respond_to?(:singleton_class) obj.singleton_class else class << obj self end end end |