Skip to content

Instantly share code, notes, and snippets.

@sferik
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sferik/6c8fb685e5291cae44e3 to your computer and use it in GitHub Desktop.
Save sferik/6c8fb685e5291cae44e3 to your computer and use it in GitHub Desktop.
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