2017-10-24 14:08:15 -04:00
|
|
|
# frozen_string_literal: true
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
|
|
|
# = ostruct.rb: OpenStruct implementation
|
|
|
|
#
|
|
|
|
# Author:: Yukihiro Matsumoto
|
|
|
|
# Documentation:: Gavin Sinclair
|
|
|
|
#
|
|
|
|
# OpenStruct allows the creation of data objects with arbitrary attributes.
|
|
|
|
# See OpenStruct for an example.
|
|
|
|
#
|
1998-01-16 07:19:09 -05:00
|
|
|
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2011-05-22 19:46:08 -04:00
|
|
|
# An OpenStruct is a data structure, similar to a Hash, that allows the
|
|
|
|
# definition of arbitrary attributes with their accompanying values. This is
|
2011-08-26 18:22:37 -04:00
|
|
|
# accomplished by using Ruby's metaprogramming to define methods on the class
|
2011-05-22 19:46:08 -04:00
|
|
|
# itself.
|
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# == Examples
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# require "ostruct"
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2011-05-22 19:46:08 -04:00
|
|
|
# person = OpenStruct.new
|
2017-03-11 16:32:46 -05:00
|
|
|
# person.name = "John Smith"
|
|
|
|
# person.age = 70
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# person.name # => "John Smith"
|
|
|
|
# person.age # => 70
|
|
|
|
# person.address # => nil
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# An OpenStruct employs a Hash internally to store the attributes and values
|
|
|
|
# and can even be initialized with one:
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# australia = OpenStruct.new(:country => "Australia", :capital => "Canberra")
|
|
|
|
# # => #<OpenStruct country="Australia", capital="Canberra">
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# Hash keys with spaces or characters that could normally not be used for
|
|
|
|
# method calls (e.g. <code>()[]*</code>) will not be immediately available
|
|
|
|
# on the OpenStruct object as a method for retrieval or assignment, but can
|
|
|
|
# still be reached through the Object#send method.
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
|
|
|
# measurements = OpenStruct.new("length (in inches)" => 24)
|
2017-03-11 16:32:46 -05:00
|
|
|
# measurements.send("length (in inches)") # => 24
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# message = OpenStruct.new(:queued? => true)
|
|
|
|
# message.queued? # => true
|
|
|
|
# message.send("queued?=", false)
|
|
|
|
# message.queued? # => false
|
2009-03-05 22:56:38 -05:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# Removing the presence of an attribute requires the execution of the
|
|
|
|
# delete_field method as setting the property value to +nil+ will not
|
|
|
|
# remove the attribute.
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# first_pet = OpenStruct.new(:name => "Rowdy", :owner => "John Smith")
|
|
|
|
# second_pet = OpenStruct.new(:name => "Rowdy")
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# first_pet.owner = nil
|
|
|
|
# first_pet # => #<OpenStruct name="Rowdy", owner=nil>
|
|
|
|
# first_pet == second_pet # => false
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2011-05-22 19:46:08 -04:00
|
|
|
# first_pet.delete_field(:owner)
|
2017-03-11 16:32:46 -05:00
|
|
|
# first_pet # => #<OpenStruct name="Rowdy">
|
|
|
|
# first_pet == second_pet # => true
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# == Implementation
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2013-02-26 22:36:02 -05:00
|
|
|
# An OpenStruct utilizes Ruby's method lookup structure to find and define the
|
2017-03-11 16:32:46 -05:00
|
|
|
# necessary methods for properties. This is accomplished through the methods
|
|
|
|
# method_missing and define_singleton_method.
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
|
|
|
# This should be a consideration if there is a concern about the performance of
|
2011-08-26 18:22:37 -04:00
|
|
|
# the objects that are created, as there is much more overhead in the setting
|
|
|
|
# of these properties compared to using a Hash or a Struct.
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
1998-01-16 07:19:09 -05:00
|
|
|
class OpenStruct
|
2015-12-28 22:48:36 -05:00
|
|
|
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2011-05-22 19:46:08 -04:00
|
|
|
# Creates a new OpenStruct object. By default, the resulting OpenStruct
|
|
|
|
# object will have no attributes.
|
|
|
|
#
|
2012-10-28 17:19:50 -04:00
|
|
|
# The optional +hash+, if given, will generate attributes and values
|
|
|
|
# (can be a Hash, an OpenStruct or a Struct).
|
2011-05-22 19:46:08 -04:00
|
|
|
# For example:
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# require "ostruct"
|
|
|
|
# hash = { "country" => "Australia", :capital => "Canberra" }
|
2004-02-19 08:42:30 -05:00
|
|
|
# data = OpenStruct.new(hash)
|
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# data # => #<OpenStruct country="Australia", capital="Canberra">
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
1998-01-16 07:19:09 -05:00
|
|
|
def initialize(hash=nil)
|
|
|
|
@table = {}
|
|
|
|
if hash
|
2012-10-28 17:19:50 -04:00
|
|
|
hash.each_pair do |k, v|
|
|
|
|
k = k.to_sym
|
|
|
|
@table[k] = v
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-11 16:32:46 -05:00
|
|
|
# Duplicates an OpenStruct object's Hash table.
|
|
|
|
def initialize_copy(orig) # :nodoc:
|
2004-02-20 05:11:25 -05:00
|
|
|
super
|
|
|
|
@table = @table.dup
|
|
|
|
end
|
|
|
|
|
2018-12-22 12:05:03 -05:00
|
|
|
#
|
|
|
|
# call-seq:
|
|
|
|
# ostruct.to_h -> hash
|
|
|
|
# ostruct.to_h {|name, value| block } -> hash
|
2012-04-23 23:46:55 -04:00
|
|
|
#
|
|
|
|
# Converts the OpenStruct to a hash with keys representing
|
2017-03-11 16:32:46 -05:00
|
|
|
# each attribute (as symbols) and their corresponding values.
|
2012-04-23 23:46:55 -04:00
|
|
|
#
|
2018-12-22 12:05:03 -05:00
|
|
|
# If a block is given, the results of the block on each pair of
|
|
|
|
# the receiver will be used as pairs.
|
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# require "ostruct"
|
|
|
|
# data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
|
|
|
|
# data.to_h # => {:country => "Australia", :capital => "Canberra" }
|
2018-12-22 12:05:03 -05:00
|
|
|
# data.to_h {|name, value| [name.to_s, value.upcase] }
|
|
|
|
# # => {"country" => "AUSTRALIA", "capital" => "CANBERRA" }
|
2012-04-23 23:46:55 -04:00
|
|
|
#
|
2018-12-22 12:05:03 -05:00
|
|
|
def to_h(&block)
|
|
|
|
if block_given?
|
|
|
|
@table.to_h(&block)
|
|
|
|
else
|
|
|
|
@table.dup
|
|
|
|
end
|
2012-04-23 23:46:55 -04:00
|
|
|
end
|
|
|
|
|
2012-10-28 17:18:53 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# :call-seq:
|
|
|
|
# ostruct.each_pair {|name, value| block } -> ostruct
|
|
|
|
# ostruct.each_pair -> Enumerator
|
2012-10-28 17:18:53 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# Yields all attributes (as symbols) along with the corresponding values
|
|
|
|
# or returns an enumerator if no block is given.
|
|
|
|
#
|
|
|
|
# require "ostruct"
|
|
|
|
# data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
|
|
|
|
# data.each_pair.to_a # => [[:country, "Australia"], [:capital, "Canberra"]]
|
2012-10-28 17:18:53 -04:00
|
|
|
#
|
|
|
|
def each_pair
|
2013-10-23 11:13:57 -04:00
|
|
|
return to_enum(__method__) { @table.size } unless block_given?
|
2012-10-28 17:18:53 -04:00
|
|
|
@table.each_pair{|p| yield p}
|
2017-02-03 13:25:28 -05:00
|
|
|
self
|
2012-10-28 17:18:53 -04:00
|
|
|
end
|
|
|
|
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2012-10-28 17:18:11 -04:00
|
|
|
# Provides marshalling support for use by the Marshal library.
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2004-12-02 23:56:25 -05:00
|
|
|
def marshal_dump
|
|
|
|
@table
|
|
|
|
end
|
2011-05-22 19:46:08 -04:00
|
|
|
|
|
|
|
#
|
2012-10-28 17:18:11 -04:00
|
|
|
# Provides marshalling support for use by the Marshal library.
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2004-12-02 23:56:25 -05:00
|
|
|
def marshal_load(x)
|
|
|
|
@table = x
|
2004-12-02 10:17:35 -05:00
|
|
|
end
|
|
|
|
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2012-10-28 17:18:11 -04:00
|
|
|
# Used internally to check if the OpenStruct is able to be
|
2012-02-14 22:31:30 -05:00
|
|
|
# modified before granting access to the internal Hash table to be modified.
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2016-03-03 00:09:02 -05:00
|
|
|
def modifiable? # :nodoc:
|
2009-02-27 00:23:10 -05:00
|
|
|
begin
|
|
|
|
@modifiable = true
|
|
|
|
rescue
|
2018-08-07 08:47:11 -04:00
|
|
|
exception_class = defined?(FrozenError) ? FrozenError : RuntimeError
|
|
|
|
raise exception_class, "can't modify frozen #{self.class}", caller(3)
|
2009-02-15 07:43:46 -05:00
|
|
|
end
|
|
|
|
@table
|
|
|
|
end
|
2016-03-03 00:09:02 -05:00
|
|
|
private :modifiable?
|
|
|
|
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2012-10-28 17:18:32 -04:00
|
|
|
# Used internally to defined properties on the
|
2011-05-22 19:46:08 -04:00
|
|
|
# OpenStruct. It does this by using the metaprogramming function
|
2012-10-28 17:19:32 -04:00
|
|
|
# define_singleton_method for both the getter method and the setter method.
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2016-03-03 00:09:02 -05:00
|
|
|
def new_ostruct_member!(name) # :nodoc:
|
2005-09-05 04:29:52 -04:00
|
|
|
name = name.to_sym
|
2015-12-31 00:37:21 -05:00
|
|
|
unless singleton_class.method_defined?(name)
|
2012-10-28 17:19:32 -04:00
|
|
|
define_singleton_method(name) { @table[name] }
|
2016-03-03 00:09:02 -05:00
|
|
|
define_singleton_method("#{name}=") {|x| modifiable?[name] = x}
|
2004-12-02 10:17:35 -05:00
|
|
|
end
|
2009-02-15 07:43:46 -05:00
|
|
|
name
|
2004-12-02 10:17:35 -05:00
|
|
|
end
|
2016-03-03 00:09:02 -05:00
|
|
|
private :new_ostruct_member!
|
|
|
|
|
2015-12-31 13:26:46 -05:00
|
|
|
def freeze
|
2016-03-03 00:09:02 -05:00
|
|
|
@table.each_key {|key| new_ostruct_member!(key)}
|
2015-12-31 13:26:46 -05:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2017-03-11 16:32:46 -05:00
|
|
|
def respond_to_missing?(mid, include_private = false) # :nodoc:
|
2015-10-14 12:57:21 -04:00
|
|
|
mname = mid.to_s.chomp("=").to_sym
|
2019-05-09 23:48:43 -04:00
|
|
|
defined?(@table) && @table.key?(mname) || super
|
2015-10-14 12:57:21 -04:00
|
|
|
end
|
|
|
|
|
2004-02-19 08:42:30 -05:00
|
|
|
def method_missing(mid, *args) # :nodoc:
|
1998-01-16 07:19:09 -05:00
|
|
|
len = args.length
|
2015-04-13 23:35:18 -04:00
|
|
|
if mname = mid[/.*(?==\z)/m]
|
1998-01-16 07:19:09 -05:00
|
|
|
if len != 1
|
2019-04-14 09:47:24 -04:00
|
|
|
raise ArgumentError, "wrong number of arguments (given #{len}, expected 1)", caller(1)
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
2016-03-03 00:09:02 -05:00
|
|
|
modifiable?[new_ostruct_member!(mname)] = args[0]
|
2017-03-28 05:21:58 -04:00
|
|
|
elsif len == 0 # and /\A[a-z_]\w*\z/ =~ mid #
|
2015-10-14 12:57:21 -04:00
|
|
|
if @table.key?(mid)
|
2016-03-03 00:09:02 -05:00
|
|
|
new_ostruct_member!(mid) unless frozen?
|
2015-10-14 12:57:21 -04:00
|
|
|
@table[mid]
|
|
|
|
end
|
2019-04-14 09:47:24 -04:00
|
|
|
elsif @table.key?(mid)
|
|
|
|
raise ArgumentError, "wrong number of arguments (given #{len}, expected 0)"
|
1998-01-16 07:19:09 -05:00
|
|
|
else
|
2017-03-28 05:21:58 -04:00
|
|
|
begin
|
|
|
|
super
|
|
|
|
rescue NoMethodError => err
|
|
|
|
err.backtrace.shift
|
|
|
|
raise
|
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
end
|
2002-11-03 06:04:35 -05:00
|
|
|
|
2012-10-28 17:20:10 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# :call-seq:
|
|
|
|
# ostruct[name] -> object
|
|
|
|
#
|
|
|
|
# Returns the value of an attribute.
|
|
|
|
#
|
|
|
|
# require "ostruct"
|
|
|
|
# person = OpenStruct.new("name" => "John Smith", "age" => 70)
|
|
|
|
# person[:age] # => 70, same as person.age
|
2012-10-28 17:20:10 -04:00
|
|
|
#
|
|
|
|
def [](name)
|
|
|
|
@table[name.to_sym]
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# :call-seq:
|
|
|
|
# ostruct[name] = obj -> obj
|
|
|
|
#
|
|
|
|
# Sets the value of an attribute.
|
2012-10-28 17:20:10 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# require "ostruct"
|
|
|
|
# person = OpenStruct.new("name" => "John Smith", "age" => 70)
|
|
|
|
# person[:age] = 42 # equivalent to person.age = 42
|
|
|
|
# person.age # => 42
|
2012-10-28 17:20:10 -04:00
|
|
|
#
|
|
|
|
def []=(name, value)
|
2016-03-03 00:09:02 -05:00
|
|
|
modifiable?[new_ostruct_member!(name)] = value
|
2012-10-28 17:20:10 -04:00
|
|
|
end
|
|
|
|
|
2015-11-17 00:36:03 -05:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# :call-seq:
|
|
|
|
# ostruct.dig(name, ...) -> object
|
|
|
|
#
|
|
|
|
# Extracts the nested value specified by the sequence of +name+
|
|
|
|
# objects by calling +dig+ at each step, returning +nil+ if any
|
|
|
|
# intermediate step is +nil+.
|
|
|
|
#
|
|
|
|
# require "ostruct"
|
|
|
|
# address = OpenStruct.new("city" => "Anytown NC", "zip" => 12345)
|
|
|
|
# person = OpenStruct.new("name" => "John Smith", "address" => address)
|
2015-11-17 00:36:03 -05:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# person.dig(:address, "zip") # => 12345
|
|
|
|
# person.dig(:business_address, "zip") # => nil
|
|
|
|
#
|
|
|
|
# data = OpenStruct.new(:array => [1, [2, 3]])
|
|
|
|
#
|
|
|
|
# data.dig(:array, 1, 0) # => 2
|
|
|
|
# data.dig(:array, 0, 0) # TypeError: Integer does not have #dig method
|
2015-11-17 00:36:03 -05:00
|
|
|
#
|
|
|
|
def dig(name, *names)
|
|
|
|
begin
|
|
|
|
name = name.to_sym
|
|
|
|
rescue NoMethodError
|
2015-12-12 16:40:50 -05:00
|
|
|
raise TypeError, "#{name} is not a symbol nor a string"
|
2015-11-17 00:36:03 -05:00
|
|
|
end
|
|
|
|
@table.dig(name, *names)
|
|
|
|
end
|
|
|
|
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# Removes the named field from the object. Returns the value that the field
|
2012-02-14 22:31:30 -05:00
|
|
|
# contained if it was defined.
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# require "ostruct"
|
|
|
|
#
|
|
|
|
# person = OpenStruct.new(name: "John", age: 70, pension: 300)
|
|
|
|
#
|
|
|
|
# person.delete_field("age") # => 70
|
|
|
|
# person # => #<OpenStruct name="John", pension=300>
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# Setting the value to +nil+ will not remove the attribute:
|
2011-05-22 19:46:08 -04:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# person.pension = nil
|
|
|
|
# person # => #<OpenStruct name="John", pension=nil>
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
1998-01-16 07:19:09 -05:00
|
|
|
def delete_field(name)
|
2010-11-03 01:17:25 -04:00
|
|
|
sym = name.to_sym
|
2015-09-26 19:16:37 -04:00
|
|
|
begin
|
2018-07-26 14:46:10 -04:00
|
|
|
singleton_class.remove_method(sym, "#{sym}=")
|
2015-09-26 19:16:37 -04:00
|
|
|
rescue NameError
|
|
|
|
end
|
|
|
|
@table.delete(sym) do
|
|
|
|
raise NameError.new("no field `#{sym}' in #{self}", sym)
|
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
2005-09-05 04:29:52 -04:00
|
|
|
InspectKey = :__inspect_key__ # :nodoc:
|
|
|
|
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
|
|
|
# Returns a string containing a detailed summary of the keys and values.
|
|
|
|
#
|
1998-01-16 07:19:09 -05:00
|
|
|
def inspect
|
2009-01-13 07:52:23 -05:00
|
|
|
ids = (Thread.current[InspectKey] ||= [])
|
|
|
|
if ids.include?(object_id)
|
2017-10-24 14:08:15 -04:00
|
|
|
detail = ' ...'
|
|
|
|
else
|
|
|
|
ids << object_id
|
|
|
|
begin
|
|
|
|
detail = @table.map do |key, value|
|
|
|
|
" #{key}=#{value.inspect}"
|
|
|
|
end.join(',')
|
|
|
|
ensure
|
|
|
|
ids.pop
|
2005-09-05 04:29:52 -04:00
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
2017-10-24 14:08:15 -04:00
|
|
|
['#<', self.class, detail, '>'].join
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
2005-09-05 04:29:52 -04:00
|
|
|
alias :to_s :inspect
|
2003-09-24 20:03:11 -04:00
|
|
|
|
2004-02-19 08:42:30 -05:00
|
|
|
attr_reader :table # :nodoc:
|
2015-01-05 00:27:31 -05:00
|
|
|
protected :table
|
2016-03-03 00:09:02 -05:00
|
|
|
alias table! table
|
2003-09-24 20:03:11 -04:00
|
|
|
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2011-05-22 19:46:08 -04:00
|
|
|
# Compares this object and +other+ for equality. An OpenStruct is equal to
|
2012-10-28 17:18:11 -04:00
|
|
|
# +other+ when +other+ is an OpenStruct and the two objects' Hash tables are
|
2011-05-22 19:46:08 -04:00
|
|
|
# equal.
|
2004-02-19 08:42:30 -05:00
|
|
|
#
|
2017-03-11 16:32:46 -05:00
|
|
|
# require "ostruct"
|
|
|
|
# first_pet = OpenStruct.new("name" => "Rowdy")
|
|
|
|
# second_pet = OpenStruct.new(:name => "Rowdy")
|
|
|
|
# third_pet = OpenStruct.new("name" => "Rowdy", :age => nil)
|
|
|
|
#
|
|
|
|
# first_pet == second_pet # => true
|
|
|
|
# first_pet == third_pet # => false
|
|
|
|
#
|
2003-09-24 20:03:11 -04:00
|
|
|
def ==(other)
|
2012-10-28 17:19:15 -04:00
|
|
|
return false unless other.kind_of?(OpenStruct)
|
2016-03-03 00:09:02 -05:00
|
|
|
@table == other.table!
|
2012-10-28 17:19:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Compares this object and +other+ for equality. An OpenStruct is eql? to
|
|
|
|
# +other+ when +other+ is an OpenStruct and the two objects' Hash tables are
|
|
|
|
# eql?.
|
|
|
|
#
|
|
|
|
def eql?(other)
|
|
|
|
return false unless other.kind_of?(OpenStruct)
|
2016-03-03 00:09:02 -05:00
|
|
|
@table.eql?(other.table!)
|
2012-10-28 17:19:15 -04:00
|
|
|
end
|
|
|
|
|
2017-03-11 16:32:46 -05:00
|
|
|
# Computes a hash code for this OpenStruct.
|
|
|
|
# Two OpenStruct objects with the same content will have the same hash code
|
|
|
|
# (and will compare using #eql?).
|
|
|
|
#
|
|
|
|
# See also Object#hash.
|
2012-10-28 17:19:15 -04:00
|
|
|
def hash
|
|
|
|
@table.hash
|
2003-09-24 20:03:11 -04:00
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|