33 Answered Questions for the topic Ruby

03/19/19

Ruby: Can I write multi-line string with no concatenation?

Is there a way to make this look a little better? conn.exec 'select attr1, attr2, attr3, attr4, attr5, attr6, attr7 ' + 'from table1, table2, table3, etc, etc, etc, etc, etc, ' + ... more

03/19/19

Why is division in Ruby returning an integer instead of decimal value?

For example: 9 / 5 #=> 1but I expected `1.8`. How can I get the correct decimal (non-integer) result? Why is it returning `1` at all?

How do I get the name of a Ruby class?

How can I get the class name from an ActiveRecord object?I have: result = User.find(1)I tried: result.class # => User(id: integer, name: string ...) result.to_s # =>... more
Ruby

03/18/19

Checking if a variable is not nil and not zero in Ruby?

I am using the following code to check if a variable is not nil and not zero if(discount != nil && discount != 0) ... endIs there a better way to do this?
Ruby

03/18/19

What is attr_accessor in Ruby?

I am having a hard time understanding `attr_accessor` in Ruby. Can someone explain this to me?
Ruby Arrays Loops

03/18/19

What is the "right" way to iterate through an array in Ruby?

PHP, for all its warts, is pretty good on this count. There's no difference between an array and a hash (maybe I'm naive, but this seems obviously right to me), and to iterate through either you... more

03/18/19

Convert string to symbol-able in Ruby?

Symbols are usually represented as such :book_author_titlebut if I have a string: "Book Author Title"is there a built in way in rails/Ruby to convert it into a symbol where I can use the `:` ... more
Ruby

02/27/15

Using Ruby Programming

Design a class Rational for fractions (n, d), d > 0 where both are relatively prime integers with gcd(n, d) = 1. Again provide constructors, accessors, mutators, to string, to double, etc. as... more

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.