Ruby General

Not learning Ruby is a bit like knowing how to fly a plane…on the ground.
Without Ruby, there is no Rails. Ruby is the backbone. It would be wise to have a reasonably solid Ruby foundation before adding on Rails. After that you will hit a certain point where you’ll realize that, in order to enact a desired feature for your web app, you’ll need to apply more advanced Ruby tactics. This will also come into play when trying to understand other developer’s code. As you move further down your Ruby learning path, your eyes will open wider to how much you can do with Ruby, and all the elegant and clever ways people apply Ruby to accomplish a given task. You will want to remember these. This stack is dedicated to capturing these moments of Ruby enlightenment.

Find all the available instance methods for a given class

03/07/16  Public, Ruby General

To see all the instance methods available on a given class

1 - from a class object call .instance_methods on the class (i.e. User.instance_methods)
or

2 - from ...

1 vote - harrylevine

Ruby Case statement (aka Switch statement)

11/20/15  Public, Ruby General

Standard Case

print "Enter your grade: "
grade = gets.chomp
case grade
when "A"
  puts 'Well done!'
when "B"
  puts 'Try harder!'
when "C"
  puts 'You need help!!!'
else
  puts "You just making it up!"
end

Mult...

1 vote - harrylevine

How the ruby Tap method works

10/09/15  Public, Ruby General

First, let's define a couple of terms: caller and mutated.

The caller is what tap is being called on. In the below, the caller is arr:

arr = [2, 3, 1]
arr.tap do |x|
  x.sort
end

Mutated permanently change...

1 vote - harrylevine

String interpolation with single and double quotes dealing with escape characters

08/14/15  Public, Testing / TDD, Ruby General

This expectation does not recognize/interpolate the @volunteer.phone_number:

expect(response.body).to include('<Message to="#{@volunteer.phone_number}">Anybody home?</Message>')

By using Ruby programming *alternate double quo...

1 vote - harrylevine

rbenv not showing the correct ruby version

06/19/15  Public, Ruby General

If you don't see the version of ruby in the list you need when you run rbenv install --list

run:

$ brew update && brew reinstall --HEAD ruby-build

then install the ruby version, i.e. rbenv install 2.2.1

From: https://github.com/H...

1 vote - harrylevine