Class: MetaMethods::Core
- Inherits:
-
Object
- Object
- MetaMethods::Core
- Includes:
- Singleton
- Defined in:
- lib/meta_methods/core.rb
Instance Method Summary collapse
- #block_to_hash(content) ⇒ Object
- #define_attribute(object, key, value) ⇒ Object
- #define_attributes(object, hash) ⇒ Object
Instance Method Details
#block_to_hash(content) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/meta_methods/core.rb', line 19 def block_to_hash content object = Object.new scope = object.send :binding object.send(:eval, content, scope) vars_list = defined_vars(object, scope) - [:content, :vars_list] extract_values(vars_list, object, scope) end |
#define_attribute(object, key, value) ⇒ Object
7 8 9 10 11 |
# File 'lib/meta_methods/core.rb', line 7 def define_attribute(object, key, value) object.singleton_class.send :attr_accessor, key.to_sym # creates accessor object.send "#{key}=".to_sym, value # sets up value for attribute end |
#define_attributes(object, hash) ⇒ Object
13 14 15 16 17 |
# File 'lib/meta_methods/core.rb', line 13 def define_attributes(object, hash) hash.each_pair do |key, value| define_attribute(object, key, value) end end |