Answer the question
In order to leave comments, you need to log in
Class Name & @?
Good afternoon dear! Who can explain to me such a thing, what is this
class Name
end
and what isdef Name
@var = var
end
def
function Name() {}
@var
return
Answer the question
In order to leave comments, you need to log in
You need to read about Ruby's classes, instance variables, and methods.
habrahabr.ru/post/48756
And yes - asking a PHP developer about Ruby is not a good idea.
A class is an entity that encapsulates data and its behavior. If we draw an analogy with js, then a class is a prototype (only in addition to behavior, it also stores data).
`@var` is an instance variable and is visible when the execution context is a particular instance of the class. Also in Ruby, the last expression evaluated is the result of the function. Similar to a function local variable in js. Something like this:function Name() { return var = 1; }
EcmaScript 6 (modern javascript) also introduced classes.
Try to run
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
"use strict";
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
calcArea() {
return this.height * this.width;
}
}
var p = new Polygon(10, 20);
alert("height = " + p.height + ", width = " + p.width + ", area = " + p.calcArea());
</script>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question