Skip to content

Instantly share code, notes, and snippets.

@Darkside73
Created March 18, 2015 09:41
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 Darkside73/1f1a34e13d585fddeb20 to your computer and use it in GitHub Desktop.
Save Darkside73/1f1a34e13d585fddeb20 to your computer and use it in GitHub Desktop.
Ruby mixin example with configurable methods
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