Created
March 18, 2015 09:41
-
-
Save Darkside73/1f1a34e13d585fddeb20 to your computer and use it in GitHub Desktop.
Ruby mixin example with configurable methods
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
require 'active_support' | |
module Connectable | |
extend ActiveSupport::Concern | |
def connect | |
puts "connecting with #{self.class.params}" | |
end | |
class_methods do | |
attr_reader :params, :timeout | |
def connect_params(params) | |
@params = params | |
end | |
def connect_timeout(timeout) | |
@timeout = timeout | |
end | |
end | |
end | |
class C | |
include Connectable | |
connect_params %w(foo bar) | |
connect_timeout 30 | |
end | |
C.new.connect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment