It took me a while to figure out what exactly plugins do.
Ruby classes are open so you can add or modify them in a plugin.
(Note: This is only one potential use of plugins. You do not need to rewrite existing classes or functions in a plugin; you can also mixin new classes.)
The following stand alone Ruby example shows the idea of a simple plugin. This is just one file of code called “example.rb” which I run using the command “ruby example.rb”
# Imagine this is a class in the Rails core
class A
def foo
"foo"
end
end
# This could be the contents of your plugin
# that redefines foo and adds the method bar
class A
def foo
"foofoo"
end
def bar
"bar"
end
end
# Now you use A in your Rails app and your plugin has
# magically been stitched into the Rails core.
a = A.new
puts a.foo # outputs "foofoo"
puts a.bar # outputs "bar"
HowTosPlugins – Some tutorials to get started
Rails Plugin Screecasts
It took me a while to figure out what exactly plugins do.
Ruby classes are open so you can add or modify them in a plugin.
(Note: This is only one potential use of plugins. You do not need to rewrite existing classes or functions in a plugin; you can also mixin new classes.)
The following stand alone Ruby example shows the idea of a simple plugin. This is just one file of code called “example.rb” which I run using the command “ruby example.rb”
# Imagine this is a class in the Rails core
class A
def foo
"foo"
end
end
# This could be the contents of your plugin
# that redefines foo and adds the method bar
class A
def foo
"foofoo"
end
def bar
"bar"
end
end
# Now you use A in your Rails app and your plugin has
# magically been stitched into the Rails core.
a = A.new
puts a.foo # outputs "foofoo"
puts a.bar # outputs "bar"
HowTosPlugins – Some tutorials to get started
Rails Plugin Screecasts