Class: Module
Instance Method Summary collapse
- #bool_accessor(*args) ⇒ Object
- #bool_reader(*args) ⇒ Object
- #bool_writer(*args) ⇒ Object
- #defer_all_other_method_calls_to(obj) ⇒ Object
- #yaml_properties(*props) ⇒ Object
Instance Method Details
#bool_accessor(*args) ⇒ Object
185 186 187 188 |
# File 'lib/sup/util.rb', line 185 def bool_accessor *args bool_reader(*args) bool_writer(*args) end |
#bool_reader(*args) ⇒ Object
181 182 183 |
# File 'lib/sup/util.rb', line 181 def bool_reader *args args.each { |sym| class_eval %{ def #{sym}?; @#{sym}; end } } end |
#bool_writer(*args) ⇒ Object
184 |
# File 'lib/sup/util.rb', line 184 def bool_writer *args; attr_writer(*args); end |
#defer_all_other_method_calls_to(obj) ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/sup/util.rb', line 190 def defer_all_other_method_calls_to obj class_eval %{ def method_missing meth, *a, &b; @#{obj}.send meth, *a, &b; end def respond_to?(m, include_private = false) @#{obj}.respond_to?(m, include_private) end } end |
#yaml_properties(*props) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sup.rb', line 25 def yaml_properties *props props = props.map { |p| p.to_s } path = name.gsub(/::/, "/") yaml_tag "!#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}" define_method :init_with do |coder| initialize(*coder.map.values_at(*props)) end define_method :encode_with do |coder| coder.map = props.inject({}) do |hash, key| hash[key] = instance_variable_get("@#{key}") hash end end # Legacy Psych.["!#{Redwood::LEGACY_YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}"] = self end |