Omanba Forum

OF Book Club: The Well-Grounded Rubyist. [Notes & Discussions]

@buildwithallan @Emp_Sel @felix_asante We’re reading and making notes, discussions, questions on The Well-Grounded Rubyist here to learn Ruby. Please jot here the most important things you learned for each chapter and add questions if you have them. Let’s keep everything in this thread.

@buildwithallan good job with the initiative :slight_smile:

PS: I’ve read that book back-to-back, twice… here to answer questions and guide discussions :smiley:

1 Like

Okay, let’s start with variables. In the book, I learn’t the 4 types of variables.

  1. local
  2. instance
  3. class
  4. global
  • Local variables start with a lower case letter or an underscore. Eg fruit, first_name. Also, when composing a variable with multiple names we should use underscore rather than camel case. So we use first_name rather than firstName
  • instance variables start with @. Eg, @last_name
  • class variables start with two at(@@) signs. eg @@total
  • global variables start with a dollar sign ($). eg $population

It seems the one I’ve got doesn’t even have all the chapters.

1 Like

Are you sure chapter 1 talks about variables? :thinking:… Here’s a PDF for the latest version @buildwithallan .

lesson 1.1.3. The variety of ruby identifiers

Looks like you’re using a different books, this is 1.1.3 for me, let’s all use the same book.

1.1.3. This is 1.3.3

From the pdf u sent.

Oooooooooo sorry. OK I see it now.

1 Like

Hello guys, sorry I was a lil busy. We will continue in the evening around 9. I hope it’s cool?

Take your time. Chapter 1 is very light, but I want to make mention of the fact that in Ruby, we don’t use class variables much, it’s good you learn about it but in practice it has problems and we don’t use it professionally, just keep it in mind. You might want to read the first answer here why class variables are bad.

I think my version of the The Well Grounded Rubyist isn’t the third edition. Let me download this one. I hope there’s no much difference.

Oh ok Thanks. what of global variables? I learned from odinproject that we shouldn’t use it. My question is will there ever be the need to use it? and when should we use it

Global variables are generally a bad idea. To put it simply if the variable is global, it means anything can access it right? Since it’s also a variable, any object or process at all can change it any time, doesn’t make any sense. Instead of a global variable, you could go for a global constant instead and possibly freeze it too. I’ve never used a global variable before, and never seen anyone use it in production. Ruby itself uses global constants instead.

You can look at some more reasons here.

1 Like

What really makes a variable global? Is just about their mode of declaration or their scope or block of code also counts?

Can a global variable or constant defined within a method or in a particular class be accessed outside their scope?

Scope.

You can try this on your machine and see :slight_smile:

1 Like

@Emp_Sel @buildwithallan are you doing chapter 2 now? Or still on chapter 1?

I am wrapping up with Chapter 1. Should be done by tomorrow. Wait a sec! Is the chapter one the same as part one? :smiley:

@siaw am done with chapter one. Can there be any code challenge or something on each chapter?

No code challenges. Idea is to read the book together, ask questions and discuss. Code challenges will come when/if we start Rails.

2 Likes

Hello, I am back. I was having internet issues. It’s been sorted out. Yes please on chapter 2. I am taking my time to read it well. Also, I am building my portfolio alongside lol

1 Like