Module: Hashstructor
- Includes:
- InstanceMethods
- Defined in:
- lib/hashstructor.rb,
lib/hashstructor.rb,
lib/hashstructor/member.rb,
lib/hashstructor/version.rb,
lib/hashstructor/class_methods.rb,
lib/hashstructor/instance_methods.rb
Overview
Allows the "hashstruction" of objects by predefining an InstanceMethods#initialize method off of the InstanceMethods#member declarations within the class spec.
The secret sauce for this module is in InstanceMethods and ClassMethods, respectively.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods Classes: HashstructorError, Member
Constant Summary collapse
- VERSION =
The gem version. As one does.
"1.0.6"
Class Method Summary collapse
-
.decorate(mod) ⇒ Object
The actual magic of both Hashstructor.prepended and Hashstructor.included; bolts the class methods onto the prepending/including module.
-
.included(mod) ⇒ Object
Fires when this module is
included. -
.prepended(mod) ⇒ Object
Fires when this module is
prepended.
Methods included from InstanceMethods
Class Method Details
.decorate(mod) ⇒ Object
36 37 38 39 |
# File 'lib/hashstructor.rb', line 36 def self.decorate(mod) mod.instance_variable_set("@hashstructor_members", []) mod.extend(Hashstructor::ClassMethods) end |
.included(mod) ⇒ Object
Fires when this module is included. This is provided for Ruby 1.9.x, but
classes that include this have to explicitly invoke
Hashstructor::InstanceMethods#hashstruct.
30 31 32 |
# File 'lib/hashstructor.rb', line 30 def self.included(mod) Hashstructor.decorate(mod) end |
.prepended(mod) ⇒ Object
Fires when this module is prepended. This is the most cromulent way to
use Hashstructor in Ruby 2.x.
23 24 25 |
# File 'lib/hashstructor.rb', line 23 def self.prepended(mod) Hashstructor.decorate(mod) end |