DEV Community

Madhu Sudhan Subedi
Madhu Sudhan Subedi

Posted on Edited on

I am learning ruby

Before get started with Ruby on Rails, I am just learning ruby programming language and I found the following facts about ruby. I am writing basics of ruby programming which I learned today.

1. Variable

  • Ruby variables are dynamic typing and duck typing
  • Can be define simply assigning value to the variable
count = 10 
awesome_count = 20 // correct convention
awesomeCount = 20 // Wrong convention
🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini 🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini
  • Yay ! we do not need any semicolon here
  • Common convention for the varible define is snake case not camel case
  • 2 Space is common practice instead of 4 space in code

2. Comment in Ruby

  • Writing comment in ruby is quite simple and straight forward
  • For e.g.
# This is ruby comment
🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini 🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini

3. Function in Ruby

  • Function can be define using 'def' like this
def double(value); value * 2; end
double(2) // results 4
🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini 🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini
  • We do not need return statement to return value too
  • In above example single line function and statement are seperated by semi-colon please do not confused on it
  • For the multiple line we can write like this
def double(value)
 value * 2
end
double(2) // results 4
🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini 🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini

Top comments (7)

🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini
 
katpadi profile image
Kat Padilla •

Good luck, fam!

🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini
 
massud1994 profile image
Madhu Sudhan Subedi •

Thank you ! Would you like to suggest me 1 book to read to get better knowledge on ruby ?

🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini
 
welearnednothing profile image
Jeff Carnes •

I’ve always been a fan of Eloquent Ruby. Unfortunately, it hasn’t been updated in some time. Still might be worth checking out.

The Rails Way is great if you’re getting into Rails.

🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini
 
abuzzany profile image
Angel Buzany •

Are you thinking write a pos about the difference between lambdas, procs and blocks?
I think It can be a good post

🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini
 
massud1994 profile image
Madhu Sudhan Subedi • • Edited

Hmm yeah, I will write posts for it after 5 days. Thanks for the suggestion !

🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini
 
rpalo profile image
Ryan Palo •

Good luck on your ruby journey! :)

🔴 Live TV: massud/i am learning ruby bb - Pertandingan Hari Ini
 
massud1994 profile image
Madhu Sudhan Subedi •

Thank you ! It's been amazing journey with ruby till now.