class Mashed::Mash

Public Class Methods

name() click to toggle source
# File lib/mashed/mash.rb, line 40
def self.name
  "Mashed::Mash"
end
new(hash) click to toggle source
# File lib/mashed/mash.rb, line 44
def initialize(hash)
  @singleton_methods ||= []
  hash = if hash.respond_to?(:to_h)
    hash.to_h
  else
    hash.to_hash
  end
  @hash = StringyHash.stringify(hash)
end

Public Instance Methods

delete(key) click to toggle source
# File lib/mashed/mash.rb, line 59
def delete(key)
  wrap_up @hash.delete(key)
end
inspect() click to toggle source
# File lib/mashed/mash.rb, line 86
def inspect
  "#<Mashed::Mash @hash=>#{@hash.inspect}>"
end
Also aliased as: to_s
is_a?(other) click to toggle source
# File lib/mashed/mash.rb, line 54
def is_a?(other)
  other == self.class
end
Also aliased as: kind_of?
kind_of?(other)
Alias for: is_a?
method_missing(symbol, *args, &blk) click to toggle source
Calls superclass method
# File lib/mashed/mash.rb, line 63
def method_missing(symbol, *args, &blk)
  string = symbol.to_s
  if blk
    super
  elsif args.length == 0
    if @hash.key?(string)
      self[string]
    elsif string =~ /\?$/
      !!self[string[0..-2]]
    else
      nil
    end
  elsif args.length == 1 && string =~ /=$/
    self[string[0..-2]] = args.first
  else
    super
  end
end
object_id() click to toggle source
# File lib/mashed/mash.rb, line 18
def object_id
  __id__
end
pretty_inspect(*) click to toggle source

I hate pry

# File lib/mashed/mash.rb, line 92
def pretty_inspect(*)
  inspect
end
pretty_print(*) click to toggle source
# File lib/mashed/mash.rb, line 96
def pretty_print(*)
  inspect
end
puts(*args) click to toggle source
# File lib/mashed/mash.rb, line 32
def puts(*args)
  ::Kernel.puts(*args)
end
respond_to?(symbol) click to toggle source
# File lib/mashed/mash.rb, line 82
def respond_to?(symbol)
  methods.map(&:to_s).include?(symbol.to_s)
end
singleton_method_added(symbol) click to toggle source
# File lib/mashed/mash.rb, line 5
def singleton_method_added(symbol)
  @singleton_methods ||= []
  @singleton_methods << symbol
end
singleton_method_removed(symbol) click to toggle source
# File lib/mashed/mash.rb, line 9
def singleton_method_removed(symbol)
  @singleton_methods ||= []
  @singleton_methods.delete symbol
end
singleton_method_undefined(symbol) click to toggle source
# File lib/mashed/mash.rb, line 13
def singleton_method_undefined(symbol)
  singleton_method_removed(symbol)
end
to_h()
Alias for: to_hash
to_hash() click to toggle source
# File lib/mashed/mash.rb, line 23
def to_hash
  unwrap @hash
end
Also aliased as: to_h
to_json(*args) click to toggle source
# File lib/mashed/mash.rb, line 28
def to_json(*args)
  to_hash.to_json(*args)
end
to_s()
Alias for: inspect

Private Instance Methods

[](key) click to toggle source
# File lib/mashed/mash.rb, line 102
def [](key)
  key = key.to_s
  wrap_up @hash[key]
end
[]=(key, value) click to toggle source
# File lib/mashed/mash.rb, line 107
def []=(key, value)
  key = key.to_s
  @hash[key] = value
end
keys() click to toggle source
# File lib/mashed/mash.rb, line 112
def keys
  @hash.keys
end
unwrap(thing) click to toggle source
# File lib/mashed/mash.rb, line 132
def unwrap(thing)
  if thing.respond_to?(:to_hash)
    thing.to_hash.each_with_object({}) do |(key, value), hash|
      hash[key] = unwrap(value)
    end
  elsif thing.respond_to?(:to_ary)
    thing.map { |t| unwrap(t) }
  else
    thing
  end
end
wrap(thing) click to toggle source
# File lib/mashed/mash.rb, line 124
def wrap(thing)
  if thing.respond_to?(:to_hash)
    self.class.new thing
  else
    thing
  end
end
wrap_up(thing) click to toggle source
# File lib/mashed/mash.rb, line 116
def wrap_up(thing)
  if thing.respond_to?(:to_ary)
    thing.map { |t| wrap(t) }
  else
    wrap(thing)
  end
end