lib/openwfe/utils.rb in openwferu-0.9.2 vs lib/openwfe/utils.rb in openwferu-0.9.3
- old
+ new
@@ -93,95 +93,84 @@
end
#
# an automatic dup implementation attempt
#
- def OpenWFE.dup (object)
+ def OpenWFE.fulldup (object)
return nil if object == nil
return object if object.kind_of? Fixnum
return object if object.kind_of? TrueClass
return object if object.kind_of? FalseClass
+ return object.dup if object.kind_of? String
+
o = object.class.new
#
# some kind of collection ?
- if object.kind_of?(Array)
+ if object.kind_of? Array
object.each do |i|
- o << dup(i)
+ o << fulldup(i)
end
- elsif object.kind_of?(Hash)
+ elsif object.kind_of? Hash
object.each do |k, v|
- o[copy(k)] = dup(v)
+ o[copy(k)] = fulldup(v)
end
end
#
# duplicate the attributes of the object
- object.instance_variables.each do | v |
+ object.instance_variables.each do |v|
#puts "v is #{v}"
value = object.instance_variable_get(v)
#puts "value is '#{value}'"
- value = dup(value)
+ value = fulldup(value)
begin
o.instance_variable_set(v, value)
- rescue Exception => e
+ rescue
# ignore, must be readonly
end
end
return o
end
def OpenWFE.to_underscore (string)
- replace_char(string, "-", "_")
+ string.gsub("-", "_")
end
def OpenWFE.to_dash (string)
- replace_char(string, "_", "-")
+ string.gsub("_", "-")
end
- def OpenWFE.replace_char (string, from, to)
- s = ""
- 0.upto(string.length) do |i|
- c = string[i, 1]
- s << if c == from
- to
- else
- c
- end
- end
- return s
- end
-
#
# Returns true if the given string starts with the 'start' string.
#
def OpenWFE.starts_with (string, start)
#
# my favourite way of doing that would be by adding this
# method to the String class, but that could be intrusive
# (as OpenWFE is meant at first as an embeddable workflow engine).
#
- return false if not string
+ return false unless string
return false if string.length < start.length
return string[0, start.length] == start
end
#
# Returns true if the given string ends with the '_end' string.
#
def OpenWFE.ends_with (string, _end)
- return false if not string
+ return false unless string
return false if string.length < _end.length
return string[-_end.length..-1] == _end
end
#