Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 1.01 KB

File metadata and controls

31 lines (23 loc) · 1.01 KB

ruby-misc-code

Just a couple notes for quick referencing in the future in case I forget.

  1. Use %Q to add double quotes around a string for cleaner looking strings that require double quotes.
puts %Q|{"message":"Malformed url #{image[:uri]}", "_id": "#{@test["_id"]}", "field_name": "#{image[:description]}"}|

A pretty good read up can be found here

  1. When including a class, the main class gets access to all the included class's methods. The included class also gets access to the main class's instance variables.
class First
  include Second
  def initialize
    @monkey = "wont do"
  end
end

class Second
  def what_about_the_monkey
    puts @monkey #prints out "wont do"
  end
end
  1. In Ruby, valid JSON requires double quotes unlike Javascript where the preferred way is with single quotes.

  2. In Ruby, the & does way too much. Good read found here