Sha256: 6c4dc7019338554be368b35b040b053d8c40ccad5067cd60ec49745c5c23bf7a
Contents?: true
Size: 673 Bytes
Versions: 10
Compression:
Stored size: 673 Bytes
Contents
# frozen_string_literal: true module Plumb class Key OPTIONAL_EXP = /(\w+)(\?)?$/ def self.wrap(key) key.is_a?(Key) ? key : new(key) end attr_reader :to_sym, :node_name def initialize(key, optional: false) key_s = key.to_s match = OPTIONAL_EXP.match(key_s) @node_name = :key @key = match[1] @to_sym = @key.to_sym @optional = !match[2].nil? ? true : optional freeze end def to_s = @key def hash @key.hash end def eql?(other) other.hash == hash end def optional? @optional end def inspect "#{@key}#{'?' if @optional}" end end end
Version data entries
10 entries across 10 versions & 1 rubygems