Ruby is a multi-platform open-source dynamic object-oriented interpreted language created by Yukihiro Matsumoto (Matz) in 1993.

learn more… | top users | synonyms

-2
votes
0answers
4 views

Ajax Responses and from Rails Controllers into a View

I've been banging my head against the wall all day and I wonder if I'm barking up the wrong tree with my approach. I have a Controller that Handles my Amazon API search requests and returns an Array ...
0
votes
0answers
16 views

Fastest way to find maximum deviation

I acknowledge that this exact question was asked here. I was working on the same problem from the same website. I had the same question and consulted the above as a reference, however with respect ...
0
votes
0answers
17 views

Creating a Custom Set Data Structure in Ruby

I wrote a set DS with some useful functions. Not sure if it is a good implementation and if there are other essential functions that a set should support. ...
3
votes
1answer
34 views

Ruby Repository Pattern

I am trying to teach myself about repository pattern in ruby. Could you please review my code. adapter.rb ...
1
vote
1answer
22 views

Speed up anagram method in Ruby

I'm working on a project to find anagrams of words. My goal is to figure out the longest anagrams out there. I took a look at my code and it works but is woefully inefficient. I have two arrays, each ...
5
votes
3answers
59 views

Structuring code that shells out to an external script

This code that shells out to an external script could use some input in order to read smoother, I think. Praise and critique are welcome. ...
5
votes
1answer
62 views

Binary Search in Ruby

I want to write a search that raises an error if the list supplied is not sorted. ...
0
votes
1answer
34 views

Improving Watir::Browser for my needs

I want to: use Watir::Browser methods without browser. instance prefix expand abilities of ...
1
vote
2answers
30 views

Removing duplication in RSpec

I’m still relatively new to the TDD scene. I’m writing a Rails app, and some duplication immediately sticks out at me in my first model spec. How else can I approach this? ...
5
votes
2answers
61 views

Rails controller method that conditionally filters results

This code for my blog checks to see if tags are in the params hash. If they are, then only posts that are tagged will be paginated. Otherwise, all of the posts are paginated. ...
4
votes
1answer
34 views

Calculation in Concern module using Rails

I wrote the following Concern module. Is it good practice to perform all the calculations in the included scope? How can it be ...
6
votes
1answer
454 views

Breaking a chess coordinate string into 2D coordinates

Given a chess coordinate as a string (e.g. "a1") I'd like to transform it into a 2-D array (so, for "a1" I'd like to get [1,1]). Here's what I came up with: ...
3
votes
5answers
94 views

All Possible Products

I'm trying to find all possible product of two 3-digit numbers. When I work with small ranges, I'm able to get an output almost instantly but when the ranges are big, it seems to take really long ...
1
vote
5answers
46 views

Refactor auto-incrementing function in Ruby on Rails

I have a Rails app where we generate calls. Each call has an incident_number which is a unique number based off the following format: 14-00001 (year in 2 digit followed by a dash then a 5 digit ...
2
votes
2answers
57 views
2
votes
1answer
30 views

Greed in Ruby Koans

I've finished the greed problem in Ruby Koans after much confusion. This is my first programming language and I have been doing fine, but then this problem really tripped me up for some reason, ...
1
vote
4answers
11 views

Issue in Ruby Programming Style

I am new to Ruby on Rails. Can some one please help me with this question? How would you modify the following to be consistent with Ruby's style? ...
2
votes
2answers
66 views

Ruby Mod 11 implementation

I wrote this Ruby Mod 11 (perhaps it's a bit generous to call it that) implementation to validate Brazilian CPF documents, which use a Mod 11 algorithm. CPF format is a 9 digit number followed by two ...
-1
votes
2answers
134 views

A platform-independent implementation of “which” in Ruby

I like to know if there's anything that I may have missed in this implementation. The method tries to provide the absolute path of the binary or script which is likely to execute based on the provided ...
3
votes
0answers
82 views

Heterogenous tree in the application domain: How do I represent them?

The Domain I have three types of items in my domain: ItemA, ItemB, ItemC. (I can't use their real names.) ItemA has one attribute: thing_id. ItemB has 6 attributes: thing_id, name, description, ...
2
votes
1answer
67 views

Bitwise operation to get the weekday name

The function days_name receive a val (string) corresponding to weekdays in hexadecimal. ...
5
votes
2answers
31 views

Adding credentialsID node to SVN location nodes

I'm new to ruby. Recently I wrote a script to add a credentialsID node to each SVN location node in each config.xml file for all ...
2
votes
1answer
50 views

Process a line in chunks via Regular Expressions with Ruby

I'm writing a Ruby script to reverse engineering message log files. They come from an external system with the following characteristics: Each line of the log file has at least one message. Each ...
3
votes
2answers
45 views

Rails Carousel View

In my web site, I created a carousel. Just now, I realized that I most likely repeated myself with this code. I would like to learn how to DRY up this code. Here is my view file (.html.erb) format: ...
3
votes
1answer
56 views

Check if a record already exists and update if it exists

I want to check if a record already exists in a database, and return true or false. If it exists, I want to update the ...
0
votes
1answer
41 views

Ruby Optimize Performance

I'm trying to do the Reverse Groups Challenge on Codeeval. My logic is function but when I try to submit my solution is says that timed out at 10 seconds. How can I improve the speed here? ...
5
votes
1answer
63 views

A conditional active record query

I have a conditional active record query that checks to see if a relationship of type X exists (.count > 0) where attribute x ...
4
votes
2answers
137 views

Reverse Game HackerRank Ruby Solution

Problem Statement Akash and Akhil are playing a game. They have N balls numbered from 0 to N−1. Akhil asks Akash to reverse the position of the balls, i.e., to change the order ...
5
votes
3answers
83 views

Cautious File Writer

I'm trying to follow the path of Sandi Metz and others who state that aiming for small and simple is good for writing understandable code. I've written a method that takes care of writing content to a ...
0
votes
1answer
68 views

Reducing the sorting time of a large number of numbers

I have to sort many large numbers in a given time limit. The program below works, but not when the test cases reaches \$10^6\$, in which case it exceeds the time limit. ...
1
vote
2answers
54 views

Ruby Anagrams Checker

I am quite new to Ruby, coming from a JavaScript background. I wrote this simple Ruby script that finds whether two strings are anagrams or not. To run it: ruby ruby_anagrams.rb 'script1' 'script2' ...
5
votes
2answers
65 views

DRYING up multiple controller action pages in Rails code

One of my rails controllers is horribly overcrowded with a bunch of methods that link to static web pages. Controller ...
4
votes
2answers
83 views

Early return, unless return value is nil [closed]

I have a lot of code that looks like this: value = TopicLinkClick.create_from(new_params) return value unless value.nil? # do something else I find this code is ...
8
votes
1answer
130 views

Spell a given number in English

I wrote a program that will take a number from 0 to 999,999,999,999 and spell out that number in English. How could I improve the readability of my code? ...
2
votes
1answer
75 views

Graceful way to iterate through two arrays and build a master array?

params[:controller_id].each do |cid| params[:zone_number].each do |pzn| zone_ids << Zone.find_by_controller_id_and_number(cid,pzn).id end end I have ...
10
votes
1answer
74 views

Object-Oriented FizzBuzz in Ruby

I don't use Ruby on a regular basis, but I felt inspired to write an extensible, object-oriented version of FizzBuzz to sharpen my skills. I welcome all feedback. The main class: ...
1
vote
1answer
33 views

Ways to express proc inside a method

I'm interested in seeing different ways the proc can be expressed inside a method that takes args. This method is meant to be a sort of FizzBuzz that will dynamically replace "Fizz" or "Buzz" as well ...
3
votes
1answer
29 views

Good approach to raise an exception

I have class House and module Lockable. Locking and unlocking House should reflect the real ...
1
vote
1answer
27 views

Checking if an associated object has failed to save/create

I smell something wrong here, but am not quite sure what the most idiomatic way to solve the problem. I have a controller for (job)listings and it has a method ...
2
votes
1answer
24 views

Find and select image files from webpage

For some reason, I feel like this is a bit messy and could be cleaner. Any suggestions? I'm selecting any image files ending in .png or ...
3
votes
1answer
27 views

Optimize mass import of XML to SQLServer in Ruby

I have the following Ruby code that's designed to update item, price and stock data for items in a MSSQL database. It's running on a Ruby 1.8.6/Rails 1.2.3 installation, in its own controller (for ...
4
votes
2answers
51 views

Generating sequence that uses the previous outcome for the current

I do not like to use while loops in Ruby. I was wondering how I can generate a "squared sequence" (e.g., squares the first input, then squares the outcome, etc.) in ...
5
votes
3answers
718 views

Repetitive controller with all methods nearly identical

I have an API with the following code ...
2
votes
3answers
52 views

Code to evaluate a dotted quad IP address has clumsy use of inject/fold - can I match the pattern in Ruby?

I wrote this to consume valid IPv4 addresses in dotted-quad decimal form. ...
7
votes
1answer
56 views

Command line flashcard game

I've built a simple command line flashcard game for learning Korean. I'm a beginner programmer, so I just wanted to make sure I'm following best practices, especially pertaining to OOP principles. ...
5
votes
2answers
42 views

Convert cardinal abbreviations into full cardinal direction

I'm still learning Ruby and I made the following function to convert "N" or "SE" into ...
4
votes
1answer
67 views

Is this a good Ruby implementation of Prime Factorization?

I'm doing some practice problems on Khan Academy. The current one is Prime factorization. I came up with this: ...
3
votes
2answers
107 views

Capitalize all words in sentence string in Ruby

I have created the following code: def LetterCapitalize(str) str = str.split(" ").each {|word| word.capitalize!} str = str.join(" ") return str end This ...
13
votes
4answers
1k views

FizzBuzz in Ruby

I have this implementation of the FizzBuzz challenge in Ruby: ...
10
votes
3answers
342 views

Git pre-commit hook to check that changes to certain files only happen on the master branch

As a beginner in Ruby, I am trying to optimize this script that is a client side pre-commit hook for git. Was hoping I could get a review to ensure I am following all ruby idioms, and to ensure I ...