Sha256: 1ab0f3baa7cb3aad73a13ebb4202cee3fb9a1aca616bd50e2470760dbf3875c3

Contents?: true

Size: 481 Bytes

Versions: 7

Compression:

Stored size: 481 Bytes

Contents

class Hash
  def method_missing(method_name, *args)
    return self[method_name] if key? method_name
    name, suffix = split_name_and_suffix(method_name)
    case suffix
    when '?'
      !!self[name.to_sym]
    when '='
      self[name.to_sym] = args[0]
    else
      self[name.to_sym]
    end
  end

  private
  METHOD_SPLITTER = /(.*?)([\?=]?)$/

  def split_name_and_suffix(method_name)
    match = method_name.to_s.match(METHOD_SPLITTER)
    [match[1], match[2]]
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jr-cli-0.6.0 lib/jr/cli/core_ext/hash.rb
jr-cli-0.5.1 lib/jr/cli/core_ext/hash.rb
jr-cli-0.5.0 lib/jr/cli/core_ext/hash.rb
jr-cli-0.4.0 lib/jr/cli/core_ext/hash.rb
jr-cli-0.3.1 lib/jr/cli/core_ext/hash.rb
jr-cli-0.3.0 lib/jr/cli/core_ext/hash.rb
jr-cli-0.2.0 lib/jr/cli/core_ext/hash.rb