lib/kameleon/compat.rb in kameleon-builder-2.1.0 vs lib/kameleon/compat.rb in kameleon-builder-2.1.1
- old
+ new
@@ -1,9 +1,10 @@
require 'securerandom'
require 'yaml'
+require 'syck'
-YAML::ENGINE.yamler = 'syck' if (defined?(Syck) || defined?(YAML::Syck)) && defined?(YAML::ENGINE)
+YAML::ENGINE.yamler = 'syck' if defined?(YAML::ENGINE)
if RUBY_VERSION < "1.9.3"
# Backport of missing SecureRandom methods from 1.9
# Snippet from http://softover.com/UUID_in_Ruby_1.8
module SecureRandom
@@ -33,7 +34,28 @@
ary[2] = (ary[2] & 0x0fff) | 0x4000
ary[3] = (ary[3] & 0x3fff) | 0x8000
"%08x-%04x-%04x-%04x-%04x%08x" % ary
end
end
+ end
+end
+
+
+class Object
+ ##
+ # @person ? @person.name :nil
+ # vs
+ # @person.try(:name)
+ def try(method)
+ send method if respond_to? method
+ end
+end
+
+class Hash
+ def self.try_convert(obj)
+ obj.try(:to_hash)
+ end
+
+ def flatten
+ to_a.flatten!
end
end