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
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
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.
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
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
Undo scaffolding in Rails?
Is there any way to 'undo' the effects of a scaffold command in Rails?
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
Ruby Ruby On Rails
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?
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 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 Code Formatting
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
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?