Skip to content

Instantly share code, notes, and snippets.

@rfletcher
Forked from wmw/to_hash.rb
Created February 3, 2011 00:15

Revisions

  1. rfletcher revised this gist Feb 3, 2011. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions to_hash.rb
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,10 @@ def initialize()
    end

    def to_hash
    hash = self.instance_variables.inject({}) do |a, e|
    hash = {e[1..-1] => self.instance_variable_get(e)}
    a.merge(hash)
    self.instance_variables.inject({}) do |a, e|
    a[e[1..-1].to_sym] = self.instance_variable_get(e)
    a
    end
    hash.symbolize_keys!
    end

    end
  2. @wmw wmw revised this gist Feb 2, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion to_hash.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    class Balls

    def initialize(outfit)
    def initialize()
    @name = 'blah'
    @caption = 'blah'
    end
  3. @wmw wmw created this gist Feb 2, 2011.
    16 changes: 16 additions & 0 deletions to_hash.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    class Balls

    def initialize(outfit)
    @name = 'blah'
    @caption = 'blah'
    end

    def to_hash
    hash = self.instance_variables.inject({}) do |a, e|
    hash = {e[1..-1] => self.instance_variable_get(e)}
    a.merge(hash)
    end
    hash.symbolize_keys!
    end

    end