Created
September 24, 2009 19:42
-
-
Save awesome/192979 to your computer and use it in GitHub Desktop.
list attr_accessors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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