Sha256: f260d4badd07c68c53f7ca603105578f9b8ef2a384df35d0e0432b9241103d51

Contents?: true

Size: 474 Bytes

Versions: 62

Compression:

Stored size: 474 Bytes

Contents

# encoding: utf-8

# Kernel
module Kernel
  # set attributes from hash
  #
  # === Example
  #
  #   class Person
  #     attr_accessor :name, :age
  #   end
  #
  #   person = Person.new
  #   person.hash_to_attributes({name: 'hoge', age: 33})
  #
  # result
  #
  #   #<PersonForHashToAttributes:0x3957858 @age=33, @not_exists="hoge">
  #
  def hash_to_attributes(hash)
    hash.each { |key, value|instance_variable_set "@#{key}", value }
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.150 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.149 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.148 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.147 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.146 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.145 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.144 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.143 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.142 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.141 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.140 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.139 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.138 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.137 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.136 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.135 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.134 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.133 lib/open_classes/kernel/hash_to_attributes.rb
tbpgr_utils-0.0.132 lib/open_classes/kernel/hash_to_attributes.rb