Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Camping (a Ruby framework)

Date:03/06/11
Author:Jakub Lédl
URL:n/a
Comments:0
Info:http://http://camping.rubyforge.org
Score: (4.00 in 2 votes)
The famous song implemented using this nice framework. When you run this, the song will be
accessible on '/bottles/<number of bottles>'.

module Bottles
  module Controllers
    class BottlesN
      def get(n)
        @count = n.to_i
        render :bottles
      end
    end
  end
  
  module Views
    def bottles
      @count.downto 1 do |cur|
        p format_bottles(cur), ' of beer on the wall, ', format_bottles(cur), ' of beer.'
        p 'Take one down and pass it around, ', format_bottles(cur - 1), ' of beer on the wall.'
      end
      p <<-beer
        No more bottles of beer on the wall, no more bottles of beer.
        Go to the store and buy some more, #{format_bottles(@count)} of beer on the wall.
        beer
    end
  end
  
  module Helpers
    def format_bottles(n)
      case n
      when 0
        "No more bottles"
      when 1
        "1 bottle"
      else
        "#{n} bottles"
      end
    end
  end
end

Camping.goes :Bottles

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: