I am studying Ruby Proc class. I don't understand why "def state="method is executed.
I also want to know why "t1.state = 1" end up with "def state=(1)"
I don't understand difference between "def state" and "def state=" ?
I can understand this connection "&proc>proc>proc.call".
# -*- coding: utf-8 -*-
class Terminal
def initialize
@connected = []
@current_state = nil
end
def connect(&proc)
@connected << proc
end
def current_input_terminal(terminal)
connect do |hoge|
terminal.state = hoge
end
end
def state=(current)
if current != 0 && current != 1
raise(ArgumentError, "input 0 or 1")
end
if @current_state != current
@current_state = current
@connected.each do |i|
i.call(current)
end
end
end
def state
@current_state
end
end
t1 = t2 = Terminal.new()
t1.current_input_terminal(t2)
t1.state = 1
puts(t2.state,t1.state)
def stateis getter whiledef state=(state)is setter - fl00r