Skip to content

alexspeller/implements

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

implements

Regulated interfaces in Ruby, much like java interfaces.

Example

module Saleable
  interface :price, :description
  
  def price_with_tax
    1.175 * price
  end
end

class Product
  implements Saleable do
  
    def price
      1.50
    end
    
    def description
      "My nice product"
    end
    
  end
end

What?

Well, this is similar to including the module. The only difference is that if the methods specified as symbols to the interface declaration aren’t defined by the end of the implements block, an error is raised. Note that normal methods from the interface module, e.g. in this case price_with_tax, will be included as usual, so Product instances will respond to price_with_tax as expected.

Why?

I was ill, and I’d had a conversation with Rob, and it seemed like a good idea at the time.

Should I use it?

No. Definitely not. It’s silly, uses ballsy class and method names that are pretty much guaranteed to conflict with something important, and is overall a pointless experiment.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add rspec for it. This is important so I don’t break it in a
    future version unintentionally.
  • Commit, do not mess with rakefile, version, or history.
    (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Alex Speller. See LICENSE for details.

About

Regulated interfaces for ruby

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages