Skip to content

Instantly share code, notes, and snippets.

@awesome
Created September 24, 2009 19:42
Show Gist options
  • Save awesome/192979 to your computer and use it in GitHub Desktop.
Save awesome/192979 to your computer and use it in GitHub Desktop.
list attr_accessors
# there may be a better way that is not ghetto,
# however I will show you how to list attr_accessors,
# actually have them returned as strings in an array:
class Awesome
attr_accessor :beer, :chips, :mullet
def initialize
@awesome = "dude"
end
end
rad = Awesome.new
def list_attr_accessor(obj)
(obj.methods - Object.methods).map {|x| x.chomp("=") if x =~ /=$/}.compact
end
list_attr_accessor(rad) # => ["beer", "chips", "mullet"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment