ismasan (owner)

Revisions

gist: 134454 Download_button fork
public
Public Clone URL: git://gist.github.com/134454.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Common pattern for including instance and class level modules
module SomeModule
  def self.included(my_class)
    my_class.extend ClassMethods
  end
 
  module ClassMethods
    def some_class_method(*args)
      # do something at class level
      puts args.inspect
    end
  end
 
  # these are instance methods
  #
  def some_instance_method(*args)
    # do something at instance level
    puts args.inspect
  end
end
 
class MyGreatClass
  include SomeModule
  
  # Now I can use the included class methods
  
  some_class_method 'Hello!'
 
end
 
# And instances methods
 
MyGreatClass.new.some_instance_method('Blah')