Sha256: b33434748bcff0c963ac4dbceaf6cbdf65e0a81918d3245453fdaa00a25eb1f5

Contents?: true

Size: 1.23 KB

Versions: 17

Compression:

Stored size: 1.23 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]

  type attribute_name = Symbol | String

  def initialize: (attribute_name, *attribute_name, ?keyword_init: boolish) ?{ () -> void } -> void

  def each: () { (Elem) -> untyped } -> untyped

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rbs-1.1.1 core/struct.rbs
rbs-1.1.0 core/struct.rbs
rbs-1.0.6 core/struct.rbs
rbs-1.0.5 core/struct.rbs
rbs-1.0.4 core/struct.rbs
rbs-1.0.3 core/struct.rbs
rbs-1.0.2 core/struct.rbs
rbs-1.0.1 core/struct.rbs
rbs-1.0.0 core/struct.rbs
rbs-1.0.0.pre2 core/struct.rbs
rbs-1.0.0.pre core/struct.rbs
rbs-0.20.1 core/struct.rbs
rbs-0.20.0 core/struct.rbs
rbs-0.19.0 core/struct.rbs
rbs-0.18.1 core/struct.rbs
rbs-0.18.0 core/struct.rbs
rbs-0.17.0 core/struct.rbs