Module: Rhom::RhomObject
Constant Summary
collapse
- @@reserved_names =
{"object" => "1",
"source_id" => "1",
"update_type" => "1",
"attrib_type" => "1",
"type" => "1",
"set_notification" => "1",
"clear_notification" => "1" }
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
we override method_missing here so that instance variables, when retrieved or set, are added to the object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/rhom/rhom_object.rb', line 28
def method_missing(name, *args)
unless name == Fixnum
varname = name.to_s.gsub(/=/,"")
setting = (name.to_s =~ /=/)
inst_var = nil
if setting
inst_var = instance_variable_set( "@#{varname}", args[0] )
else
inst_var = instance_variable_get( "@#{varname}" )
end
inst_var
end
end
|
Instance Method Details
#djb_hash(str, len) ⇒ Object
use djb hash function to generate temp object id
53
54
55
56
57
58
59
|
# File 'lib/rhom/rhom_object.rb', line 53
def djb_hash(str, len)
hash = 5381
for i in (0..len)
hash = ((hash << 5) + hash) + str[i].to_i
end
return hash
end
|
61
62
63
|
# File 'lib/rhom/rhom_object.rb', line 61
def (arr=[])
arr.last.is_a?(::Hash) ? arr.pop : {}
end
|
#method_name_reserved?(method) ⇒ Boolean
74
75
76
|
# File 'lib/rhom/rhom_object.rb', line 74
def method_name_reserved?(method)
@@reserved_names.has_key?(method)
end
|
#remove_var(name) ⇒ Object
44
45
46
|
# File 'lib/rhom/rhom_object.rb', line 44
def remove_var(name)
remove_instance_variable("@#{name}")
end
|
#strip_braces(str = nil) ⇒ Object
48
49
50
|
# File 'lib/rhom/rhom_object.rb', line 48
def strip_braces(str=nil)
str ? str.gsub(/\{/,"").gsub(/\}/,"") : nil
end
|