Class: WEEL::ManipulateHash

Inherits:
Object
  • Object
show all
Defined in:
lib/weel.rb

Overview

}}}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values, touched, changed) ⇒ ManipulateHash

Returns a new instance of ManipulateHash.



202
203
204
205
206
# File 'lib/weel.rb', line 202

def initialize(values,touched,changed)
  @__weel_values = values
  @__weel_touched = touched
  @__weel_changed = changed
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/weel.rb', line 220

def method_missing(name,*args)
  if args.empty? && @__weel_values.key?(name)
    @__weel_touched << name
    @__weel_values[name]
  elsif name.to_s[-1..-1] == "=" && args.length == 1
    temp = name.to_s[0..-2]
    @__weel_changed << temp.to_sym
    @__weel_values[temp.to_sym] = args[0]
  elsif name.to_s == "[]=" && args.length == 2
    @__weel_changed << args[0]
    @__weel_values[args[0]] = args[1]
  elsif name.to_s == "[]" && args.length == 1
    @__weel_touched << args[0]
    @__weel_values[args[0]]
  else
    nil
  end
end

Instance Attribute Details

#__weel_changedObject (readonly)

{{{



200
201
202
# File 'lib/weel.rb', line 200

def __weel_changed
  @__weel_changed
end

#__weel_touchedObject (readonly)

{{{



200
201
202
# File 'lib/weel.rb', line 200

def __weel_touched
  @__weel_touched
end

Instance Method Details

#clearObject



215
216
217
218
# File 'lib/weel.rb', line 215

def clear
  @__weel_changed += @__weel_values.keys
  @__weel_values.clear
end

#delete(value) ⇒ Object



208
209
210
211
212
213
# File 'lib/weel.rb', line 208

def delete(value)
  if @__weel_values.key?(value)
    @__weel_changed << value
    @__weel_values.delete(value)
  end
end