Sha256: 64da687ba88cd1e5f534c6af341f6a9438797b29f5dd53aab3bd0519b0777477

Contents?: true

Size: 1.28 KB

Versions: 17

Compression:

Stored size: 1.28 KB

Contents

# A [Struct](Struct) is a convenient way to bundle a
# number of attributes together, using accessor methods, without having to
# write an explicit class.
# 
# The [Struct](Struct) class generates new subclasses
# that hold a set of members and their values. For each member a reader
# and writer method is created similar to
# [Module\#attr\_accessor](https://ruby-doc.org/core-2.6.3/Module.html#method-i-attr_accessor)
# .
# 
# ```ruby
# Customer = Struct.new(:name, :address) do
#   def greeting
#     "Hello #{name}!"
#   end
# end
# 
# dave = Customer.new("Dave", "123 Main")
# dave.name     #=> "Dave"
# dave.greeting #=> "Hello Dave!"
# ```
# 
# See [::new](Struct#method-c-new) for further
# examples of creating struct subclasses and instances.
# 
# In the method descriptions that follow, a "member" parameter refers to a
# struct member which is either a quoted string ( `"name"` ) or a
# [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html) ( `:name` ).
class Struct[Elem] < Object
  include Enumerable[Elem, Struct[Elem]]

  def initialize: (Symbol | String arg0, *Symbol | String arg1, ?keyword_init: bool keyword_init) -> void

  def each: () { (Elem arg0) -> untyped } -> untyped
          | () -> self

  def self.members: () -> ::Array[Symbol]

  def new: (*untyped args) -> Struct[untyped]
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
rbs-0.11.0 stdlib/builtin/struct.rbs
rbs-0.10.0 stdlib/builtin/struct.rbs
rbs-0.9.1 stdlib/builtin/struct.rbs
rbs-0.9.0 stdlib/builtin/struct.rbs
rbs-0.8.0 stdlib/builtin/struct.rbs
rbs-0.7.0 stdlib/builtin/struct.rbs
rbs-0.6.0 stdlib/builtin/struct.rbs
rbs-0.5.0 stdlib/builtin/struct.rbs
rbs-0.4.0 stdlib/builtin/struct.rbs
rbs-0.3.1 stdlib/builtin/struct.rbs
rbs-0.3.0 stdlib/builtin/struct.rbs
rbs-0.2.0 stdlib/builtin/struct.rbs
steep-0.16.0 vendor/ruby-signature/stdlib/builtin/struct.rbs
steep-0.15.0 vendor/ruby-signature/stdlib/builtin/struct.rbs
steep-0.14.0 vendor/ruby-signature/stdlib/builtin/struct.rbs
steep-0.13.0 vendor/ruby-signature/stdlib/builtin/struct.rbs
steep-0.12.0 vendor/ruby-signature/stdlib/builtin/struct.rbs