30 Answered Questions for the topic Ruby

Describe the four pillars of object oriented programming

Encapsulation, Inheritance, Abstraction, Polymorphism

Creating An Air Pollution Index Reader in Ruby (Straight Forward Question)

I got stuck halfway with this question, im unable to post the image because im required to get 10 reputation points here lol. So i literally recreated the whole question here. There were no files... more

Is dynamic language always interpreted?

Looking at most (if not all) dynamic languages [i.e Python, PHP, Perl and Ruby], they are all interpreted. Correct me if I'm wrong. Is there any example of dynamic language that goes through... more

06/13/19

Safe integer parsing in Ruby?

I have a string, say `'123'`, and I want to convert it to `123`.I know you can simply do `some_string.to_i`, but that converts `'lolipops'` to `0`, which is not the effect I have in mind. I want it... more
Ruby

06/12/19

Map and Remove nil values in Ruby?

I have a map which either changes a value or sets it to nil. I then want to remove the nil entries from the list. The list doesn't need to be kept.This is what I currently have:<!-- language:... more
Ruby

06/11/19

How to document Ruby code?

Are there certain code conventions when documenting Ruby code? For example I have the following code snippet: require 'open3' module ProcessUtils # Runs a subprocess and applies... more
Ruby Regex

06/07/19

Match all occurrences of a regex?

Is there a quick way to find every match of a regular expression in Ruby? I've looked through the Regex object in the Ruby STL and searched on Google to no avail.
Ruby

06/07/19

How many types of variables are used in Ruby and what are they?

Test whether a Ruby class is a subclass of another class?

I would like to test whether a class inherits from another class, but there doesn't seem to exist a method for that. class A end class B < A end B.is_a? A => false ... more
Ruby Terminal

06/07/19

How to execute a Ruby script in Terminal?

I've set everything up that I need on my Mac (Ruby, Rails, Homebrew, Git, etc), and I've even written a small program. Now, how do I execute it in Terminal? I wrote the program in Redcar and saved... more
Ruby

06/06/19

What is the difference between the Object methods clone and dup?

06/06/19

Undo scaffolding in Rails?

Is there any way to 'undo' the effects of a scaffold command in Rails?
Ruby String

05/30/19

How to check whether a string contains a substring in Ruby?

I have a string variable with content as follows: varMessage = "hi/thsid/sdfhsjdf/dfjsd/sdjfsdn\ " "/my/name/is/balaji.so\ " ... more

05/30/19

How do I create an average from a Ruby array?

How would get find an average from an array?If I have the array: [0,4,8,2,5,0,2,6]Averaging would give me 3.375.Thanks!
Ruby

05/29/19

Is There a Better Way of Checking Nil or Length == 0 of a String in Ruby?

Is there a better way than the following to check to see if a string is nil OR has a length of 0 in Ruby?<!-- language: lang-Ruby --> if !my_string || my_string.length == 0 return... more

Why are exclamation marks used in Ruby methods?

In Ruby some methods have a question mark (`?`) that ask a question like `include?` that ask if the object in question is included, this then returns a true/false.But why do some methods have... more

05/22/19

In Ruby, how do I skip a loop in a .each loop, similar to 'continue'?

In Ruby, how do I skip a loop in a `.each` loop, similar to `continue` in other languages?
Ruby Operators

05/22/19

Difference between "and" and && in Ruby?

What is the difference between the `&&` and `and` operators in Ruby?

04/29/19

How to split a delimited string in Ruby and convert it to an array?

I have a string `"1,2,3,4"` and I'd like to convert it into an array: [1,2,3,4]How?
Ruby String

04/28/19

Ruby capitalize every word first letter?

I need to make the first character of every word uppercase, and make the rest lowercase... manufacturer.MFA_BRAND.first.upcaseis only setting the first letter uppercase, but I need this: ALFA... more

04/12/19

How to make a HTTP request using Ruby on Rails?

I would like to take information from another website. Therefore (maybe) I should make a request to that website (in my case a HTTP GET request) and receive the response. How can I make this in... more

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

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.