Skip to content

Special Characters In Ruby Method Names

Yesterday I watched a short video on Code School’s Website regarding special character methods in Ruby.  It was a very interesting screencast.  What I learned that was most valuable to me is that special characters in method names are there only for the purpose of being expressive.

Take this sample class as an example from the video:

In this sample code, for the Banana class, the “tasty?” method has a question mark as a special character.  However, the question mark really has no value when it comes to syntax.  The “tasty?” method will execute the same way even if the question mark is absent from the method name.  However, by convention, the special character is written to be more expressive when reading the code.

This actually helped me quite a bit because I kept wondering why special characters exist in some method names and not others.  Now, I have the answer.

Finally, just in case this code doesn’t make any sense to you, here is an explanation of what it’s doing:

This is a Ruby class and the initialize method creates (or constructs) an instance of a banana.  The “tasty?” method is just a boolean that says if a banana object is black, then it’s not tasty, else it is tasty.  What’s interesting to note here is that you could instantiate this class multiple times, and each instance could be either tasty or not tasty depending on each individual object’s color.

If this doesn’t make sense right now, don’t worry.  I’ll cover classes in more detail later as I work my way through my learning material.  Until next time!

Advertisements

The Web And Web Technology

Since my end game is ultimately to be a Rails developer, I thought it would be a good idea to brush up on my understanding of the Internet and the technologies involved with standard web development.  Knowing Ruby is key to being a Rails developer, but there are other technologies that must be understood in order to be a good Rails developer (html, css, javascript, http and http requests, databases, etc).

Udacity has a great course for learning (or brushing up) on these kinds of things.  In Udacity’s course entitled Web Development(CS253), the entire course is spent building a blog.  However, it doesn’t just focus on the server side language.  Rather, it focuses on the entire web stack.  I’ll be enrolling in this course in order make sure I have a solid foundation in fundamental web technologies.

So, just to summarize, here is my current method of learning:

Learn To Program: The Fundamentals for helping to make sure I have a solid foundation in core programming paradigms
Programming Ruby (Book) for learning the fundamentals of the Ruby programming language
Model Thinking for helping to think through and organize information logically for the purpose of writing better and more logical code
Web Development for the purpose of making sure I have a solid foundation in core web technologies

So, I have a pretty full plate of learning over the next few weeks, but I feel quite invigorated in this quest.

Model Thinking

According to Programming Ruby, pages 15-16, here is how one should think about object-oriented programming:

When you write object-oriented programs, you’re normally looking to model concepts from the real world.  During this modeling process you’ll discover categories of things that need to be represented in code.  In a jukebox, the concept of a “song” could be such a category.  In Ruby, you’d define a class to represent each of these entities.  A class is a combination of state (for example, the name of the song) and methods that use that state (perhaps a method to play the song).

As I was browsing Coursera’s catalog, I saw an interesting course called Model Thinking.  This particular course is an interesting concept because it teaches us to think about the real world in terms of models so that one may think more intelligently and clearly about the world in which we live.  And, this course is not limited to one particular field of study.  The course teaches one to think about managing information for decision making and problem solving in any field of study.

When I saw this, I immediately thought of the quote listed above.  Object-oriented programming is modeling real world concepts in computer code.  It just makes sense to me that improving my thinking about models can only help to improve my ability to solve problems in code.  And, it should help me to write better, more logically organized code.

I think I’ve found my structure and focus for the next few weeks.  I’m going to continue working my way through the Programming Ruby book, I’m going to help my thinking about the real world by learning more about Model Thinking, and I’m going to get practical, hands-on experience writing code in a structured environment with the  Learn To Program: The Fundamentals course.

From what I can see, this looks like a winner all the way around.

Link

Learn To Program: The Fundamentals

Just a few minutes ago, I signed up for Learn To Program: The Fundamentals through Coursera.  I’ve tried a similar course through Coursera before, but they were using Javascript as the base language for the course.  Frankly, I didn’t find learning with pure Javascript to be a lot of fun.  This time, however, they are using Python (I’ve not used Python a lot, but it’s syntax is similar enough to Ruby that I should be able to learn and apply the concepts).

Although I’m already decently familiar with the core paradigms of programming, I find that I often need help applying those concepts in the real world towards solving problems.  For the most part, I just need to write more code.  That’s the bottom line.  However, I often have a hard time thinking about what to do and what kind of problem to solve.  This course should help me with that as we work through real examples in a structured environment.

The class begins September 24 and it lasts seven weeks.  I’m very much looking forward to it.  Once I’m finished, I plan to add the certificate to my Linkedin profile and my resume.  Until next time.

Pragmatic Programmers: Programming Ruby Chapter 1

I just finished reading chapter 1 of Programming Ruby.  I didn’t really need the command prompt tutorial nor did I need the installation instructions.

However, the section on accessing the Ruby documentation from the command line using RDoc and ri was really helpful.  I never knew you could actually access the Ruby documentation locally from the command line.  One of the class examples used to demonstrate the RDoc and ri capability was the GC class.  The GC class provides an interface to Ruby’s garbage collector.  I never knew Ruby had this b/c garbage collection and managing the heap is usually reserved for lower-level, compiled languages.

I wish I had this book a year ago.  I’m already reading through chapter 2 and loving it!  I’ll post my thoughts from chapter 2 once I finish reading and working through all code examples.

 

Pragmatic Programmers: Programming Ruby

I ordered this yesterday and can’t wait for it to get here: Programming Ruby

I already own “The Well-Grounded Rubyist”.  Fantastic book.  You can find it here: The Well-Grounded Rubyist  I haven’t finished this one yet, but I’m working my way through it.  I’ll try to post some book reviews in the coming weeks as I progress through the material.  

My Journey Into Ruby

Well, here goes nothing.  I’ve been dabbling in Ruby programming for about two years now.  I’ve put in lot of time and effort into learning bits and pieces of Ruby and Ruby on Rails, but now it’s time to put some structure to all of this learning and really get serious about becoming a Ruby developer.  I want to be someone that can solve problems with Ruby rather than just someone that can focus on specific issues that have already been solved.

This is going to be a huge task.  But, I’m making my journey public so that I can get better and so that I can take structured steps to becoming a real Ruby developer rather than a “shade tree” Ruby developer.  Here’s to my journey!  May this inspire others to do the same.

Here is the link to my public Github site: https://github.com/pmgraham