Sha256: b5b17929845b205158dead0bffa1a61604854346aae5e9cd1babdab0615acd08

Contents?: true

Size: 600 Bytes

Versions: 2

Compression:

Stored size: 600 Bytes

Contents

#          Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

# Extensions for Struct

class Symbol
  undef_method :to_int if method_defined?(:to_int)
end

class Struct

  # Example:
  #  Point = Struct.new(:x, :y)
  #  point = Point.new(15, 10)
  #  point.values_at(:y, :x)
  #  # => [10, 15]
  #  point.values_at(0, 1)
  #  # => [15, 10]

  def values_at(*keys)
    if keys.all?{|key| key.respond_to?(:to_int) }
      keys.map{|key| values[key.to_int] }
    else
      keys.map{|k| self[k] }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ramaze-0.3.0 lib/ramaze/snippets/struct/values_at.rb
ramaze-0.3.5 lib/ramaze/snippets/struct/values_at.rb