Reputation: 459
The code below checks to see if in the file '08_book_titles' I have reversed the string that is in the class Book and method title contained in the code below. That string being "inferno".
require '08_book_titles'
describe Book do
before do
@book = Book.new
end
describe 'title' do
it 'should capitalize the first letter' do
@book.title = "inferno"
@book.title.should == "Inferno"
end
I tried the following to no avail. Any help is much appreciated.
class Book
def title
return yield.capitalize
end
end
Upvotes: 1
Views: 129
Reputation: 1136
If you want to store the capitalized form, then
class Book
attr_accessor :title
def title=( title )
@title = title.capitalize
end
end
If you want to preserve the original form
class Book
attr_accessor :title
def title
@title.capitalize
end
end
Upvotes: 2