Module: Hashifiable

Defined in:
lib/hashifiable.rb,
lib/hashifiable/version.rb

Defined Under Namespace

Modules: Version

Constant Summary collapse

VERSION =
Version.to_s

Instance Method Summary collapse

Instance Method Details

#hashify(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hashifiable.rb', line 4

def hashify(*args)
  ## Defines to_hash with specified arguments.
  define_method :to_hash do
    hash_representation = {}
    args.each do |attribute|
      hash_representation[attribute] = self.send(attribute)
    end

    hash_representation
  end

  ## Defines to_json based on the to_hash method.
  define_method :to_json do
    self.to_hash.to_json
  end
end