Skip to content

Instantly share code, notes, and snippets.

@IceDragon200
Created April 21, 2015 15:45
Show Gist options
  • Save IceDragon200/3f9a2f02064ba2706dd8 to your computer and use it in GitHub Desktop.
Save IceDragon200/3f9a2f02064ba2706dd8 to your computer and use it in GitHub Desktop.
class Object
# Attempts to wrap the object into an Array if it isnt already one.
#
# @return [Array]
def to_arylist
[self]
end
end
class Array
# (see Object#to_arylist)
def to_arylist
self.dup
end
end
# var1 = {a:2,c:3}; var2 = [{a:2,c:3}]; [var1, var2].map { |obj| obj.to_arylist } #=> [[{:a=>2, :c=>3}], [{:a=>2, :c=>3}]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment