Skip to content

Instantly share code, notes, and snippets.

@timrandg
Created February 7, 2012 07:50
Show Gist options
  • Select an option

  • Save timrandg/1758102 to your computer and use it in GitHub Desktop.

Select an option

Save timrandg/1758102 to your computer and use it in GitHub Desktop.
module GeneralInit
def initialize(*h)
if h.length == 1 && h.first.kind_of?(Hash)
h.first.each { |k,v| instance_variable_set("@#{k}",v) }
end
end
end
class Me
include GeneralInit
def sort
instance_variables.sort{|a,b| instance_variable_get(b) <=> instance_variable_get(a)}
end
end
m = Me.new(tim:10, josh:20, ben: 13, sue:1991)
p m.sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment