Skip to content

Instantly share code, notes, and snippets.

@sumanmukherjee03
Created May 24, 2013 18:39
Show Gist options
  • Save sumanmukherjee03/5645626 to your computer and use it in GitHub Desktop.
Save sumanmukherjee03/5645626 to your computer and use it in GitHub Desktop.
Another example of how to use barewords in ruby.
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