Fizz Buzz in Ruby for dummies

Spoiler alert: I am a true novice. Tasked with figuring out fizz buzz in ruby for a class and while I have found more than a few versions of code that solve the problem, my understanding is so rudimentary that I cannot figure out how these examples truly work. First question(refer to spoiler alert if … Read more

Determining type of an object in ruby

The proper way to determine the “type” of an object, which is a wobbly term in the Ruby world, is to call object.class. Since classes can inherit from other classes, if you want to determine if an object is “of a particular type” you might call object.is_a?(ClassName) to see if object is of type ClassName or derived from it. Normally type checking … Read more

p vs puts in Ruby

p foo prints foo.inspect followed by a newline, i.e. it prints the value of inspect instead of to_s, which is more suitable for debugging (because you can e.g. tell the difference between 1, “1” and “2\b1”, which you can’t when printing without inspect).

Rails: I installed Ruby, now “bundle install” doesn’t work

Bundle with Ruby 2.1.6 You just need to install bundler : This will be installed in a gemset specific to ruby-2.1.6, so it won’t interfere with anything you installed with ruby-2.3.0. You can use to install the required gems. Trying with Ruby 2.3.0 Alternatively, you could just try the example you downloaded with ruby-2.3.0 by … Read more

Ruby: kind_of? vs. instance_of? vs. is_a?

kind_of? and is_a? are synonymous. instance_of? is different from the other two in that it only returns true if the object is an instance of that exact class, not a subclass. Example: “hello”.is_a? Object and “hello”.kind_of? Object return true because “hello” is a String and String is a subclass of Object. However “hello”.instance_of? Object returns … Read more