Sha256: b7ba7183cd523a5e3191e142ae1217ffb0125e6f97078040064c3432234c5691

Contents?: true

Size: 568 Bytes

Versions: 24

Compression:

Stored size: 568 Bytes

Contents

# A struct that only allows keyword arguments.
# For example, this should be used to create value objects that are returned from service methods,
# instead of just returning a hash.
#
# Usage:
#   class Foo < Percy::KeywordStruct.new(:bar, :baz, :qux)
#   end
#
#   foo = Foo.new(bar: 123, baz: true)
#   foo.bar  # --> 123
#   foo.baz  # --> true
#   foo.qux  # --> nil
#   foo.fake # --> raises NoMethodError
module Percy
  class KeywordStruct < Struct
    def initialize(**kwargs)
      super(kwargs.keys)
      kwargs.each { |k, v| self[k] = v }
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
percy-common-3.1.9 lib/percy/keyword_struct.rb
percy-common-3.1.8 lib/percy/keyword_struct.rb
percy-common-3.1.7.pre.beta lib/percy/keyword_struct.rb
percy-common-3.1.6 lib/percy/keyword_struct.rb
percy-common-3.1.5 lib/percy/keyword_struct.rb
percy-common-3.1.4 lib/percy/keyword_struct.rb
percy-common-3.1.3 lib/percy/keyword_struct.rb
percy-common-3.1.2 lib/percy/keyword_struct.rb
percy-common-3.1.2.pre.rc.3 lib/percy/keyword_struct.rb
percy-common-3.1.2.pre.rc.2 lib/percy/keyword_struct.rb
percy-common-3.1.2.rc.1 lib/percy/keyword_struct.rb
percy-common-3.1.1 lib/percy/keyword_struct.rb
percy-common-3.1.0 lib/percy/keyword_struct.rb
percy-common-3.0.2 lib/percy/keyword_struct.rb
percy-common-3.0.1 lib/percy/keyword_struct.rb
percy-common-3.0.0 lib/percy/keyword_struct.rb
percy-common-2.1.1 lib/percy/keyword_struct.rb
percy-common-2.1.0 lib/percy/keyword_struct.rb
percy-common-2.0.0 lib/percy/keyword_struct.rb
percy-common-1.5.0 lib/percy/keyword_struct.rb