Skip to content

Instantly share code, notes, and snippets.

@trshafer
Created July 13, 2011 19:08
Show Gist options
  • Save trshafer/1081064 to your computer and use it in GitHub Desktop.
Save trshafer/1081064 to your computer and use it in GitHub Desktop.
Module extension within module, post class inclusion
module FourToedFrontFeet
def number_of_toes
4
end
end
module Quadruped
include FourToedFrontFeet
def number_of_legs
4
end
end
class Bear
extend Quadruped
end
puts "#{Bear.number_of_toes * Bear.number_of_legs + 2} toes" # 18 toes
module WalksOnAllFours
def walking_stance
"all fours"
end
end
module Quadruped
include WalksOnAllFours
def can_stand_on_two_legs?
true
end
end
puts Bear.can_stand_on_two_legs? # true
puts Bear.walking_stance # undefined method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment