Can't output currency in ruby with money-gem

If I run this code: require “money” price1 = Money.new(100) price2 = Money.new(2000) total = price1 + price2 puts total I get a I18n::InvalidLocale error: [path to ruby]/gems/i18n-0.7.0/lib/i18n.rb:284:in `enforce_available_locales!’: :en is not a valid locale (I18n::InvalidLocale) What can I do to avoid this problem?

Trying to parse string from a website that gives device status with a value at the end

I’m using ruby and trying to get a value from a string that I received from an URI.PARSE. Below is what I get back from the URI.PARSE and is in my string. You can see it in the result at the bottom. Q8:0; I only need the Device which in this case is Q8 and […]

Ruby on Rails tutorial part two

I keep getting stock [sic] in a RoR tutorial. Part 1 is here. After doing that, I ran the command: rails generate devise User Not sure if that is the correct code to type as the tutorial is not clear. I’m not sure what the command does, and which files are connected to what etc. […]

Select consecutive integers from array in Ruby

I want to select consecutive integers from an array, for example: Input: (doesn’t have to be sorted) array = [1, 3, 6, 7, 8, 9, 10, 12, 13, 17] Expected output: #=> [6, 7, 8, 9, 10, 12, 13] This is my code so far: array = [1, 3, 9, 6, 7, 10, 8, 12, […]

How to get the reference alive to the older one, when there is a second exception in Ruby?

begin raise “explosion” rescue p $! raise “Are you mad” p $! end # #<RuntimeError: explosion> # RuntimeError: Are you mad # from (irb):5:in `rescue in irb_binding’ # from (irb):1 # from /usr/bin/irb:12:in `<main>’ $! always holds only the current exception object reference. But is there any way to get a reference to the original […]

Installing Ruby via RVM fails to configure

I’m trying to install Ruby via RVM by running rvm install 1.9.3 but am getting a bunch of errors: Error running env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include ./configure –prefix=/Users/kuzjaved/.rvm/usr, please read /Users/kuzjaved/.rvm/log/ruby-1.9.3-p327/yaml/configure.log Error running make, please read /Users/kuzjaved/.rvm/log/ruby-1.9.3-p327/yaml/make.log Error running env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include ./configure –enable-shared –disable-install-doc –prefix=/Users/kuzjaved/.rvm/rubies/ruby-1.9.3-p327 –with-opt-dir=/Users/kuzjaved/.rvm/usr, please read /Users/kuzjaved/.rvm/log/ruby-1.9.3-p327/configure.log There has been an error […]

How to replace a pattern in a string

I built a page that is rendered differently depending on params. The logic is something like this: <% if params[:x] == “1” %> <!–render version A–> <% elsif params[:x] == “2” %> <!–render version B–> <% elsif params[:x] == “3” %> <!–render version C–> <% end %> I want each version to have two links […]

User Input + Random Word and Number printing

So I have code: puts ‘What is your name?(Enter in field below)’ input = gets.chomp puts ‘end’ occupationslist = [‘Engineer’, ‘Clerk’, ‘Doctor’, ‘Demolition Expert’, ‘Athlete’, ‘None’,] oclistlength = occupationslist.length rand1 = rand(oclistlength) occupation = ocupationslist[rand1] def occupations puts input puts ‘Occupation: ‘ + occupation puts ‘Rating: ‘ + rand(1-12).to_s end occupations It is supposed to […]

How to calculate the number of ways to represent n cents

This question already has an answer here: How to find all combinations of coins when given some dollar value 32 answers

How could I split commas excepts it's in double quotes

s1 =’a,b,c,”x,y,z” ‘ m1 = s1.split(‘,’) “x,y,z” should not be splitted by comma The expected result should be [‘a’,’b’,’c’,”x,y,z”], total size is 4 How could I do that in Ruby

Ruby is the best programming language in the world - Ruby on Rails.