Ruby variable types and variable scope

Explore the available variable data types in the Ruby programming language and see the differences in variable scope. This is a key tutorial in learning about Ruby since variable scoping issues can lead to code bugs that are difficult to find. Go through the full guide: http://rails.devcamp.com/ruby-programming/ruby-variables/variable-scope-and-variable-types-in-ruby

Comments

TheB10K says:

This is not accurate. Instance variables are available to all methods of that instance of the class. How you described @jobs would only be true for a local variable. Try it yourself: https://repl.it/repls/ClutteredUnconsciousTench

Jennifer Rosse Hamm says:

Well explained!

Thomas Minnick says:

Great video

ripperx444 says:

I don’t understand Ruby syntax for :set_job vs @set_job and why only: has the “:” on the other side.

Python

Class Test:
Def __init__(self, name):
Self.name = name
def printName(self):
print(self.name)

In Ruby you can’t even access name unless you have a getter and setter or the shorthand which kinda makes me wonder why even code in this language. It’s almost like it’s trying to be like Java and a Python hybrid.

The other thing Ruby does oddly is essentially static variables that get mutated via inheritance for all classes. It was a little strange as i dont see the use case for having it.

Overall amazing tutorial for someone trying to come from Java and Python to Ruby(not by choice lol) but hey you gotta do what you gotta do!

 Write a comment

*

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!