Skip to content

Instantly share code, notes, and snippets.

@sferik sferik/exposable.rb
Last active Aug 29, 2015

Embed
What would you like to do?
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
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
You can’t perform that action at this time.