Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 85815

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

2 votes
Accepted

Finding the object and the URL associated with a notification

First, object_id is a built-in method of Object in Ruby, so I recommend renaming this field to model_id to avoid any clashes. …
Spike's user avatar
  • 1,423
2 votes
Accepted

Print multiplication tables

def print_multiplication_table(max) I think size would be a better name for the argument. max sounds like it's the largest number in the table. pad = (1 + (max*max).to_s.length) Rename to col …
Spike's user avatar
  • 1,423
0 votes

Method for gathering the correct data to a specific user

Time.zone.now.strftime('%V').to_i Use Date#cweek to get the calendar week number: Time.zone.now.to_date.cweek
Spike's user avatar
  • 1,423
12 votes
2 answers
1k views

Minesweeper: how many mines are near?

Minesweeper in Ruby (from exercism.io): Write a program that adds the numbers to a minesweeper board. …
Spike's user avatar
  • 1,423
2 votes
Accepted

Is dynamically generating routes from Model enum safe?

Place.send(params[:category]) Using raw user data with send is very dangerous, as it allows the user to call any method (params[:category] could be "delete_all" for example). Using raw user data w …
Spike's user avatar
  • 1,423
1 vote
Accepted

TicTacToe game with functional AI in ruby - follow-up

(In ruby you don't have to declare "instance variables / fields" to use them) Also, make all internal methods private so they are not accessible from outside the class. …
Spike's user avatar
  • 1,423
2 votes

Debug statement remover

Suggested solution: #USAGE: <input source> | ruby debug_converter.rb <comment symbol> > <output file> raise "Wrong number of args: #{ARGV.inspect}" if ARGV.length ! …
Spike's user avatar
  • 1,423
4 votes
Accepted

Knight's Travails in ruby

Bug This: knight_moves([2,5],[2,5]) prints: Your path is: [2, 5] [4, 6] [2, 5] Not the shortest path. In knight_moves, simply call bfs with [first_child] as the children argument. There's no ne …
Spike's user avatar
  • 1,423
1 vote
Accepted

Usertool For Website Admins -- Follow up

Bug Adding a user with a username that is already taken overwrites the existing user. Adding a user with a blank username is allowed. (Maybe you should allow alphanumeric characters only, and set a …
Spike's user avatar
  • 1,423
1 vote
Accepted

Bidirectional map

Your code looks good. I only found an edge case with rehash, missing functionality in fetch, and some minor fixes. h ? new_from_hash(h) : nil This can be written as: h && new_from_hash(h) def …
Spike's user avatar
  • 1,423
2 votes

Rails conditional sorting based on params

@bids = current_user.bids.select { |bid| bid.real_property_sale.try(:real_property_sale_project).try(:failed_date).nil? } if ... @bids = @bids.select { |bid| ... } elsif ... @bids = @bids.s …
Spike's user avatar
  • 1,423
2 votes
Accepted

Converting ASCII to an image

class Array def chunk(chunk_size) self.each_with_index.with_object(Array.new(size / chunk_size) { [] }) do |(elt, ind), result| result[ind / chunk_size] << elt end end end You re …
Spike's user avatar
  • 1,423
2 votes

TicTacToe game with functional AI in ruby - follow-up

I will review the Board class. def display_board puts "\e[H\e[2J" # ANSI clear @board.each_slice(3).with_index do |row, idx| print " #{row.join(' | ')}\n" puts ' ---+---+---' unless idx …
Spike's user avatar
  • 1,423
4 votes
Accepted

Ruby Command Line Tic-Tac-Toe

Not bad. Unbounded recursion Inside the Game class: def initialize # ... play_game end def play_game @player1 = Player.new("X") @player2 = Player.new("O") # ... play_again end def pl …
Spike's user avatar
  • 1,423
4 votes
Accepted

Unlocking spreadsheet files quickly

Don't put your method inside Kernel. Rename ls_grep to something more descriptive, e.g. unlock_spreadsheet. The two shell commands (cd and ls|grep) aren't needed. The code doesn't depend on the curre …
Spike's user avatar
  • 1,423