I have a fairly simple class that begins:
class Binding
include Observable
def initialize(variable)
@variable = variable
@state = variable.dup
@log = Log.instance.log
end
# and so on...
In a testcase setip for Binding
I have @test_binding = Binding.new(@test_variable)
but I get the error
"NoMethodError: undefined method
new' for Binding:Class C:/Users/Tim/RubymineProjects/LPA/Tests/binding_test.rb:25:in
setup'
I've looked at some of the other questions here with almost the same title, but none of them seem to apply.
Can anybody tell me what I'm doing wrong?
Can anybody tell me what I'm doing wrong?
Actually you are not doing anything wrong in that code. The fact is that the Binding
class already exists in Ruby therefore what you are actually doing is reopening another class rather than defining a new one.
Particularly the Binding
class doesn't have the new
class method, which is the cause of the problem.
You have two reasonable choices now:
The first implies that you have to come up with another name, which is hardly what you want. The other can be thought as putting a class into a module/package/container of your own so that you distinguish what classes are part of your library and what are built ins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With