M
M
Meridian3122013-12-22 11:50:17
ruby
Meridian312, 2013-12-22 11:50:17

How can you use = methods in Ruby?

I'm learning Ruby, after C++, I don't understand the following method=, is it a call to the method method and the value is immediately assigned to the object? or how to interpret it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
_
_ _, 2013-12-22
@Meridian312

Yes, this is a setter, quite simply :)
Ruby allows you to use some characters in method names.
Therefore, there are valid?, select! methods.
object.value = 10 is the same as object.value=(10), which in C++ would be object.setValue(10)

S
sdevalex, 2013-12-22
@sdevalex

This is a setter. Ruby doesn't have public variables. Only getters, setters and internal variables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question