lib/lotus/utils/attributes.rb in lotus-utils-0.3.3 vs lib/lotus/utils/attributes.rb in lotus-utils-0.3.4
- old
+ new
@@ -46,21 +46,32 @@
#
# attributes = Lotus::Utils::Attributes.new(a: 1, 'b' => 2, 23 => 'foo')
#
# attributes.get(:a) # => 1
# attributes.get('a') # => 1
+ # attributes[:a] # => 1
+ # attributes['a'] # => 1
#
# attributes.get(:b) # => 2
# attributes.get('b') # => 2
+ # attributes[:b] # => 2
+ # attributes['b'] # => 2
#
# attributes.get(23) # => "foo"
# attributes.get('23') # => "foo"
+ # attributes[23] # => "foo"
+ # attributes[23] # => "foo"
#
# attributes.get(:unknown) # => nil
# attributes.get('unknown') # => nil
+ # attributes[:unknown] # => nil
+ # attributes['unknown'] # => nil
def get(attribute)
@attributes[attribute.to_s]
end
+
+ # @since 0.3.4
+ alias_method :[], :get
# Set the given value for the given attribute
#
# @param attribute [#to_s] a String or any object that implements #to_s
# @param value [Object] any value