Class: Hash

Inherits:
Object show all
Defined in:
lib/kiss/ext/core.rb

Overview

Methods to enable hash.attr == hash syntax, including hash.id and hash.type

Direct Known Subclasses

Hashay, Kiss::Login

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



136
137
138
139
140
141
142
143
144
145
# File 'lib/kiss/ext/core.rb', line 136

def method_missing(meth, *args)
  meth = meth.id2name
  if meth =~ /=\Z/
    self[meth[0...-1]] = (args.length<2 ? args[0] : args)
  elsif meth.to_s =~ /(\w+)\?\Z/
    !(self[$1] || self[$1.to_sym]).zero?
  else
    self[meth] || self[meth.to_sym]
  end
end

Instance Method Details

#idObject



146
147
148
# File 'lib/kiss/ext/core.rb', line 146

def id
  self['id'] || self [:id]
end

#prepend_html(*args) ⇒ Object



153
154
155
# File 'lib/kiss/ext/core.rb', line 153

def prepend_html(*args)
  self[:body].prepend_html(*args)
end

#to_query_stringObject



157
158
159
# File 'lib/kiss/ext/core.rb', line 157

def to_query_string
  self.keys.map {|k| "#{k.url_escape}=#{self[k]}" }.join('&')
end

#typeObject



149
150
151
# File 'lib/kiss/ext/core.rb', line 149

def type
  self['type'] || self [:type] || Hash
end