Skip to content

Instantly share code, notes, and snippets.

@zvlex
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save zvlex/ac142caa4716d124eb8e to your computer and use it in GitHub Desktop.

Select an option

Save zvlex/ac142caa4716d124eb8e to your computer and use it in GitHub Desktop.
my Hashie Mash basic implementation
class Mash
def initialize
@mash = {}
end
def method_missing(method_id, *args)
string_method = method_id.to_s
if is_predicate?(method_id)
key = string_method[0...-1]
@mash.include?(key)
else
if args.empty?
@mash[string_method]
else
key = string_method[0...-1]
@mash[key] = args.join
@mash[key]
end
end
end
def is_predicate?(method)
return true if method =~ /[a-zA-z]\?\z/
false
end
end
mash = Mash.new
p mash.hello?
mash.hello = "let me say"
p mash.hello
p mash.hello?
p mash.alex?
mash.alex = "Ruby Programming Language"
p mash.alex?
p mash.alex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment