Questions tagged [ruby]

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

Filter by
Sorted by
Tagged with
8
votes
1answer
1k views

Custom grep in Ruby

I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely ...
7
votes
2answers
1k views

Higher lower game in Ruby

I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely ...
5
votes
1answer
4k views

Transactions and locking in Rails 3

I am new to Rails and have a system that needs to process transactions. A user can enter a transaction to which one or more users are tied. These users owe some amount of money to the person making ...
13
votes
2answers
7k views

Handling many networking exceptions in Ruby

What would be a prettier/faster way to do handling of multiple errors in Ruby? Here is the code I am working with: ...
6
votes
1answer
399 views

How and where to define a partial helper module

I want to split my helpers in different modules (and files), but I found some problems which I got around with the following solution: ...
11
votes
3answers
5k views

Ruby Koans Proxy Project

I've just finished the Ruby Koans and one of the last projects was creating a Proxy class that sends methods to another class. I was wondering whether you would change anything about my solution (if ...
4
votes
1answer
169 views

Nicer way to work params [closed]

...
5
votes
3answers
566 views

Formatting a possibly nil value as hours and minutes

This might be a bit silly because there are like a thousand ways to do this, but I'm struggling to come up with one that I like. I feel like this should fit in one line, but I don't like re-using ...
4
votes
1answer
941 views

Cleaning up a multi-model view in Rails3

I'm new to rails and have built a multi-model form. It's working, but some of the code doesn't feel right. The model code is below. I'm using Devise for my user authentication: ...
2
votes
3answers
509 views

Extracting and mangling a parameter from a MySQL configuration file

Is there a better way of doing this? ...
3
votes
2answers
418 views

Add data of unknown type to a hash

I don't see any way to refactor this, but something tells me I'm missing something. ...
3
votes
3answers
276 views

Counting subscribers with matching ZIP code, interests, and sex

I am trying to cycle through a few of these blocks. They basically narrow down a number of people that fulfill a bunch of attributes. I apologize if this seems really messy, but my database is really ...
4
votes
1answer
391 views

Find associated object if exists, otherwise generate it in ruby

I have a simplified model that looks like this: ...
2
votes
2answers
221 views

Setting responses on survey results

The below code feels ugly, how can I make it better? (The part i don't like is the ||=. I also don't know if I like the resulting data structure. (An array of hashes) ...
3
votes
1answer
282 views

Fluid tag for displaying GitHub Gists with noscript tags in a Jekyll post

A while back I wrote a Fluid tag for Jekyll that inserts the contents of a GitHub Gist into the content of the page in <noscript> tags for RSS readers. I've ...
6
votes
1answer
333 views

Refactor Helper methods

I have two helper methods that return li for view with the li for current view having id as selected. ...
6
votes
1answer
604 views

Splitting log file into smaller files

I had a file that looked like this: ...
6
votes
1answer
393 views

How to manage different views

I answered a question in stackoverflow but I gave a solution that looks a little dirty to me, I'd like your opinion because I think there is a much smarter way to do it. A guest user should be able ...
10
votes
2answers
492 views

Ruby script on-all-nodes-run not only for teaching

I wrote the following Ruby script several years ago and have been using it often ever since on a Bioinformatics computer cluster. It pulls out a list of hosts from the Torque queuing system ...
7
votes
1answer
351 views

Collecting friends' wall posts

Originally, I had everything in the base method #read_wall(). I'm not sure what happened with the array, but when I tried: array = result + second + third + fourth....
9
votes
3answers
1k views

Storing a Ruby app's settings

I have used code which looks a little like this in an app I'm working on: ...
10
votes
2answers
5k views

Return render in Ruby on Rails

Is it bad to do return render? I am doing this to NOT also allow a redirect. ...
5
votes
2answers
611 views

Rails view to list users in a zebra-striped table

...
4
votes
1answer
3k views

Ruby on rails complex select statement…there has to be a better way!

I am building a query that could end up look like this: ...
7
votes
1answer
2k views

Developing a multistep form

I implemented a multistep form with the method described by Ryan Bates in ep217 but I had some weird behavior when refreshing or moving between the steps Acts_as_good_style (old but still good) has a ...
11
votes
4answers
4k views

Displaying the multiples of a given number

Here's a method I made that's supposed to print out multiples of any numbers up to any quantity: ...
7
votes
1answer
814 views

Avoiding sub-queries in named scopes

I use named scopes all over the place. When I have a named scope that deals with two different tables, I tend to query the second table in a sub-query. That way, if I mix and match with other tables ...
10
votes
2answers
415 views

A text editor driven file renamer in Ruby

I wrote the following Ruby script several years ago and have been using it often ever since. It opens a text editor with the list of files in current directory. You can then edit the file names as ...
4
votes
1answer
418 views

Autodetecting monitors in XFCE

I got sick of manually xrandering things on my computers (especially since I always just sequence monitors from left to right and set each at the highest resolution) so I wrote this: ...
1
vote
4answers
934 views
26
votes
4answers
14k views

Unit-testing a controller in Ruby on Rails

I intend this to be a general question on writing an effective set of test cases for a controller action. I include the following ingredients: Ruby on Rails RSpec: A testing framework. I considered ...
8
votes
1answer
235 views

RubyGem for Enums

A little background first. I've been working on a fairly large Rails application which quickly grew into a breeding ground for "smelly" code. One antipattern we were using a lot was storing objects ...
8
votes
1answer
21k views

Filtering (search) a model with multiple params in hash

This function in my Profile model receive a hash from a search form and should filter the table depending on those values. I guess there is something like a pattern ...
22
votes
2answers
3k views

Ruby Koans' Greed Task

Having coded in Java and C# for quite some years, I'm currently learning Ruby. I'm working my way through the Ruby Koans tutorial. At some point, you are to implement a method that calculates the game-...
17
votes
4answers
1k views

Genetic algorithm for Clever Algorithms project

I wrote a bunch of Ruby code for a book project I've just finished. One criticism is that it is fine code but not very "ruby like". I agree my style was simplified for communication reasons, and ...
3
votes
5answers
11k views

Avoiding null in variable assignment

I want to get empty string or the string value of the object Which code you will use and why? value = object.to_s or this ...
23
votes
5answers
22k views

Use of a regex stored inside a YAML file

I installed settingslogic and in the configuration file I put the regex for the email as follows: ...
7
votes
1answer
1k views

Object cache storage for Rails

I want to have fast cache in which I want to keep all my nomenclature data. I don't want to go with Memcached because I have to do serialize/de-serialize on each object which is slow. So I choose to ...