I think you're getting confused by the class instance variable @view
.
When you access an instance variable, the "instance" being referred to is self
. In an instance method, self
is the instance of the class (as you would expect). In a class, self
is the class itself (an instance of Class
)! This should illustrate the distinction:
class Foo
@x = 0
def initialize
@x = 1
end
def self.x
@x
end
def x
@x
end
end
Foo.x # 0
Foo.new.x # 1
Foo.x # still 0, they are entirely separate variables
When you extend Dialect::Generator::Assertion
, url_is
is added as a class method to Test
, so @url
is being set as an instance variable for Test
itself. But when you include Dialect
, view
is added as an instance method to Test
so the @url
it is accessing is for an instance of Test
.
In the view
method, you can simply specify that you need the class version of the variable
def view
self.class.class_eval { "#{@url}" }
end