32 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


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


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


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 File Io


How to write to file in Ruby?

I need to read the data out of database and then save it in a text file.How can I do that in Ruby? Is there any file management system in Ruby?
Ruby Regex


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.


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


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


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


Undo scaffolding in Rails?

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


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


What does the "map" method do in Ruby?

I'm new to programming. Can someone explain what `.map` would do in: params = (0...param_count).map


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!


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


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


Difference between "and" and && in Ruby?

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


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


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


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


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

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.


Find an Online Tutor Now

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