Last active
August 29, 2015 14:07
-
-
Save sferik/6c8fb685e5291cae44e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'set' | |
module Lotus | |
module Action | |
module Exposable | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def attr_reader(*names) | |
self.attributes = names | |
super | |
end | |
def attributes=(names) | |
attributes | |
@attributes += names | |
end | |
def attributes | |
@attributes ||= Set.new | |
end | |
end | |
def attributes | |
self.class.attributes.each_with_object({}) do |attribute, result| | |
result[attribute.to_sym] = public_send(attribute) | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or 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
class Show | |
include Lotus::Action::Exposable | |
attr_reader :color | |
def call | |
@color = '#c0ffee' | |
end | |
end | |
__END__ | |
> s = Show.new | |
=> #<Show:0x007f86b8aa0938> | |
> Show.attributes | |
=> #<Set: {:color}> | |
> s.call | |
=> "#c0ffee" | |
> s.attributes | |
=> {:color=>"#c0ffee"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment