Ruby

Discussion on other languages at the COJ. This is the place to clear your doubts about these languages, and to share with the community the new things you learn about them.
User avatar
Phantom
Posts: 58
Joined: 7 years ago
Location: Cuba
Gender: None specified

Ruby

Post by Phantom » 6 years ago

Ok pepe!! Ruby is coming... Ruby like Python, is a very powerfull language. Whitout shame... ask me, and... we can discuss about it. I recommend you Python and Ruby... the future in the present.



User avatar
jelara
Posts: 37
Joined: 7 years ago
Location: Guadalajara, Mexico
Gender: Male
Mexico

Re: Ruby

Post by jelara » 6 years ago

I have heard a lot of great things about Ruby, and to learn it has been on my "to do" list for a while now.

But of course, for contest programming I still recommend you guys C++: nothing compares to the speed of this language (you know, because there is no VM running it). Those extra seconds can mean the difference between an AC and a TLE (and I speak from experience here :lol:).

But yes, Ruby is coming. We will continue working to add to our judge as many languages as possible.

User avatar
Phantom
Posts: 58
Joined: 7 years ago
Location: Cuba
Gender: None specified

Ruby

Post by Phantom » 6 years ago

My opinion is the same. C and C++ are very fast, that don’t have discussion. But… in C and C++ you have to implement almost everything. Itch! That is a problem… and big! For example, in Ruby for the big powers of 3 you most only write:
puts 3**gets.to_i
In Pthon:
print 3**input()
-->The numbers in Python and Ruby are very big. In this languages aren’t the problems of the numbers of 32 and 64 bits.
-->In Python and Ruby you don’t need write the type of a variable, the language recognize it in execution time. This is a powerful and interesting tool, because that made dynamic the variables. If you want, I'll explain you this philosophy deeper.
For example… in C,C++,C#,Java,… you would write:
int pepe = 56;
In Python and Ruby you only write:
pepe=56
Moreover, you can write after:
pepe=”friend”
And now pepe isn’t a integer, is a string.
-->In Python and Ruby you can return different things in a same method:
In Ruby:
def Something(bool)
return bool ? 56 : "pepe is my friend"
end
In Python:
def Something(bool):
return 56 if bool else “pepe is my friend”
-->I thing I have stop here because I excite easy with the facilities of this languages. We will see in a next class. :D

User avatar
Robbin
Posts: 38
Joined: 7 years ago
Location: Santiago de Cuba
Gender: None specified

Re: Ruby

Post by Robbin » 6 years ago

People tell me that Ruby is a strong language..
can you tell me something about it?

User avatar
Robbin
Posts: 38
Joined: 7 years ago
Location: Santiago de Cuba
Gender: None specified

Re: Ruby

Post by Robbin » 6 years ago

well, that's it:
what's the principal structure on a ruby program?

User avatar
Phantom
Posts: 58
Joined: 7 years ago
Location: Cuba
Gender: None specified

Re: Ruby

Post by Phantom » 6 years ago

Jajajaja In my opinion, Ruby is a strong language for the same reason that Python is a strong language. If you understand why Python is a strong language, you understand why Ruby is a strong language. In my opinion Python and Ruby is almost the same, with the difference that one recognize for indentation and the other, no (have another big differences, but I said that for you can have an idea in the similarity).
Can you be more specific when you say “structure”? Because I understand by “structure” many things.

User avatar
Robbin
Posts: 38
Joined: 7 years ago
Location: Santiago de Cuba
Gender: None specified

Re: Ruby

Post by Robbin » 6 years ago

a simple program, the basic program, hello world!!, for example
and the declaration of a function..
I gotta go..

User avatar
Phantom
Posts: 58
Joined: 7 years ago
Location: Cuba
Gender: None specified

Re: Ruby

Post by Phantom » 6 years ago

Here your example…:

def printHelloWorld()
--puts "Hello World!!"
end

printHelloWorld()


I put the “Hello World” in a function, because you want the declaration of a function.
In Ruby are a “print” too, but “print” is like a “printf(“Hello World”);” in C++ (without the ‘\n’ at the end). You see?? Is almost like Python. :)

User avatar
Robbin
Posts: 38
Joined: 7 years ago
Location: Santiago de Cuba
Gender: None specified

Re: Ruby

Post by Robbin » 6 years ago

I see.. so I don´t have to write the ":" when I declare a function, rigth??

And, how can I read variables from the keyboard in ruby??
It´s interesting..

User avatar
Phantom
Posts: 58
Joined: 7 years ago
Location: Cuba
Gender: None specified

Re: Ruby

Post by Phantom » 6 years ago

In the previous post I wrote how you can read variables from the keyboard in ruby, but, fine, I´ll repat it.

In Ruby you read with "gets" and the string have methods to convert to "int" or to other types:
For example, to convert a string to int:
pepe = "45"
pepe = pepe.to_i
#Now pepe is equal to 45(interger)

For this reason, you can write:
pepe = gets.to_i

See it!!!
"to_i" is a function. I have not commit an error in write "pepe.to_i" and not "pepe.to_i()". In Ruby the parenthesis is optional.

Post Reply

Return to “Other languages”