Forum: RSpec [Cucumber] attribute readers in World?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ee6788c2faaad7a5cd0bc466c9ea60d8?d=identicon&s=25 aidy lewis (Guest)
on 2009-04-14 14:45
(Received via mailing list)
Hi,

#env.rb
class ProjectWorld
  include Spec::Matchers

  def browser
    @browser ||= Browser.new
  end
end

World do
  ProjectWorld.new
end

Instead of using explicit getters here, can I not use attribute readers?

Aidy
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-04-14 14:59
(Received via mailing list)
On Tue, Apr 14, 2009 at 2:19 PM, aidy lewis
<aidy.lewis@googlemail.com>wrote:

>
> World do
>  ProjectWorld.new
> end
>
> Instead of using explicit getters here, can I not use attribute readers?
>

You can, as long as you initialize @browser in initialize. It would be
almost the same (eager instead of lazy instantiation)

Aslak
This topic is locked and can not be replied to.