Class | SuperStruct |
In: |
lib/whois/answer/super_struct.rb
lib/whois/answer/super_struct.rb |
Parent: | Struct |
SuperStruct is an enhanced version of the Ruby Standar library Struct.
Compared with the original version, it provides the following additional features:
Overwrites the standard Struct initializer to add the ability to create an instance from a Hash of parameters.
attributes = { :foo => 1, :bar => "baz" } Struct.new(attributes) # => #<Struct foo=1, bar="baz">
If block is given, the block is called on self.
# File lib/whois/answer/super_struct.rb, line 40 def initialize(*args, &block) if args.first.is_a? Hash initialize_with_hash(args.first) else super end yield(self) if block_given? end
Overwrites the standard Struct initializer to add the ability to create an instance from a Hash of parameters.
attributes = { :foo => 1, :bar => "baz" } Struct.new(attributes) # => #<Struct foo=1, bar="baz">
If block is given, the block is called on self.
# File lib/whois/answer/super_struct.rb, line 40 def initialize(*args, &block) if args.first.is_a? Hash initialize_with_hash(args.first) else super end yield(self) if block_given? end