Sha256: 71f9300332be81bf97fd736944f28b197216d90576e8442009ac36e4d9e37feb

Contents?: true

Size: 631 Bytes

Versions: 2

Compression:

Stored size: 631 Bytes

Contents

class Object
  
  ##
  # Returns a hash indifferent to symbols or strings for 
  # accessor keys.
  #
  # === Examples
  #
  #   hash = indifferent_hash
  #   hash['foo'] = 'bar'
  #
  #   hash[:foo]  #=> 'bar'
  #   hash['foo'] #=> 'bar'
  #
  
  def indifferent_hash
    Hash.new { |hash, key| hash[key.to_s] if key.is_a? Symbol }
  end
  
  ##
  # Yield and return +value+.
  #
  # === Examples
  #
  #   people = []
  #   people << 'tj'
  #   people << 'foo'
  #
  #   returning [] do |people|
  #     people << 'tj'
  #     people << 'foo'
  #   end
  #
  
  def returning value, &block
    yield value
    value
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
visionmedia-rext-0.2.1 lib/rext/object/helpers.rb
visionmedia-rext-0.2.2 lib/rext/object/helpers.rb