Iacutone.rb

coding and things

Extend and Include in Ruby

| Comments

I have been trying to clean up some old code with Ruby modules. This post is to help me remember the differences between include and extend in Ruby.

1
2
3
class Foo
  extend ActionView::Helpers::NumberHelper
end
1
2
3
module Foo
  extend ActionView::Helpers::NumberHelper
end
1
2
Foo.number_to_currency 2
 => "$2.00"
1
2
3
class Foo
  include ActionView::Helpers::NumberHelper
end
1
2
3
foo = Foo.new
foo.number_to_currency 2
 => "$2.00"

Comments