class Bud::TupleStruct

FIXME: Should likely override hash and eql? as well.

Public Class Methods

new_struct(cols) click to toggle source
# File lib/bud/monkeypatch.rb, line 20
def self.new_struct(cols)
  $struct_lock.synchronize {
    ($struct_classes[cols] ||= Bud::TupleStruct.new(*cols))
  }
end

Public Instance Methods

+(o) click to toggle source
# File lib/bud/monkeypatch.rb, line 65
def +(o)
  self.to_ary + o.to_ary
end
<=>(o) click to toggle source

XXX: This only considers two TupleStruct instances to be equal if they have the same schema (column names) AND the same contents; unclear if structural equality (consider only values, not column names) would be better.

# File lib/bud/monkeypatch.rb, line 29
def <=>(o)
  if o.class == self.class
    self.each_with_index do |e, i|
      other = o[i]
      next if e == other
      return e <=> other
    end
    return 0
  elsif o.nil?
    return nil
  else
    raise "Comparison (<=>) between #{o.class} and #{self.class} not implemented"
  end
end
==(o) click to toggle source
Calls superclass method
# File lib/bud/monkeypatch.rb, line 44
def ==(o)
  if o.class == self.class
    return super
  elsif o.class == Array
    return false if self.length != o.length
    self.each_with_index do |el, i|
      return false if el != o[i]
    end
    return true
  end
  false
end
eql?(o) click to toggle source
# File lib/bud/monkeypatch.rb, line 61
def eql?(o)
  self == o
end
hash() click to toggle source
# File lib/bud/monkeypatch.rb, line 57
def hash
  self.values.hash
end
inspect() click to toggle source
# File lib/bud/monkeypatch.rb, line 73
def inspect
  self.to_a.inspect
end
Also aliased as: to_s
to_msgpack(out=nil) click to toggle source
# File lib/bud/monkeypatch.rb, line 69
def to_msgpack(out=nil)
  self.to_a.to_msgpack(out)
end
to_s()
Alias for: inspect