Created
May 24, 2013 18:39
-
-
Save sumanmukherjee03/5645626 to your computer and use it in GitHub Desktop.
Another example of how to use barewords in ruby.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
require 'forwardable' | |
RSpec.configure do |config| | |
config.mock_with :rspec | |
config.color_enabled = true | |
end | |
module Version | |
NUMBER = 1 | |
def version | |
"Version #{NUMBER}" | |
end | |
end | |
class Service | |
def initialize(type) | |
@type = type | |
end | |
def service | |
"makes #{@type}" | |
end | |
end | |
class ImpService | |
include Version | |
extend Forwardable | |
SALUTATION = "Hola Master" | |
attr_reader :imps_name | |
def_delegators :'@service', :service | |
def initialize(name, service_name) | |
@imps_name = name | |
@service = Service.new(service_name) | |
end | |
def salutation | |
SALUTATION | |
end | |
def prog_name | |
self.class.name | |
end | |
def message(firstname, lastname) | |
masters_name = "#{firstname} #{lastname}" | |
"#{salutation} #{masters_name}! Welcome to #{prog_name} program #{version}. #{imps_name}, the imp serves you. He #{service} very well." | |
end | |
end | |
describe "barewords" do | |
it "greets the master with a welcome message" do | |
ImpService.new("Toby", "Coffee").message("Alexander", "Dann").should eq("Hola Master Alexander Dann! Welcome to ImpService program Version 1. Toby, the imp serves you. He makes Coffee very well.") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment