Ruby is a multi-platform, open-source, dynamic, object-oriented, interpreted language created by Yukihiro Matsumoto (Matz) in 1993.
0
votes
0answers
10 views
Array of date by each week
I have two dates, example :
date1 = "4-02-2017".to_date
date2 = "4-02-2017".to_date + 29
I try to get array of date by each week with this :
...
0
votes
1answer
21 views
Class for Stripe transactions
I just wonder whether it is a common approach to hit the third-party API and fetch values within the initialize method?
Ex.
...
0
votes
0answers
40 views
Programming Noob Chris Pine Tutorial sorting without use of array.sort method [closed]
" Let's write a program which asks us to type in as many words as we
want (one word per line, continuing until we just press Enter on an
empty line), and which then repeats the words back to us in
...
0
votes
0answers
45 views
Find all permutations in an array of string in ruby
I was at the job interview yesterday. And there is a question that asks me to find all the permutations in an array of string in ruby:
input: ['abc', 'cba', 'ab', 'ba', 'acbdef']
output: ['abc'...
2
votes
1answer
50 views
Displaying model statistics (as a sentence) in a view
A Rails 4.2 app has three models:
User
Author
Quote
... and the following associations:
users HABTM authors
author has_many quotes
If the user is associated with any authors, his "profile" view ...
4
votes
1answer
56 views
Single Linked List Implementation in Ruby
The #traverse_until method is a helper function that traverses the linked list and returns the node and index of the node once a condition (in a block) is met or until the end of the list. I would ...
-3
votes
1answer
43 views
How to refactor code from Rails controller to model when there are session variables?
I have the following controller:
...
0
votes
0answers
52 views
Listing employees, categorized by license expiration date
I am working on a personal project and I have hit a wall. I know I am writing bad code and I really want to refactor the code below. The application has three tables on the same page. Each table ...
1
vote
1answer
49 views
Expense family script
I wrote a script in Ruby for a better family budget overview. The expenses are hold under a CSV file. Any feedback is welcomed!
...
4
votes
2answers
98 views
Yet another vowel counting program
Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.
Since I've been trying to learn Ruby, I decided to ...
1
vote
1answer
95 views
Use an existing invoice if one exists, else create one
Here are the requirements:
If initial_invoice? is false, existing_invoice always exists.
If ...
2
votes
0answers
37 views
Send email from job queue, save status, acknowledge and log info
I'm writing code for a worker receiving message from a queue.
It should
send an email
save the fact that this email has been sent
acknowledge the job
log some info.
I wrote the following code, but ...
1
vote
0answers
42 views
Rails Calendar Generation Method
I have this helper method that generates an HTML calendar based on the current day:
...
1
vote
1answer
60 views
Replacing the vowels of a string with the letter “X”
This code replaces every vowel of the string with "X":
...
7
votes
1answer
82 views
SFTP Ruby script for downloading files from server
I have written this Ruby script to download some file from server using SFTP. Help me improve this one.
Find the original script at this link
...
1
vote
0answers
22 views
Declarative method to return a stack of paths
I'm building a stack of paths that each lead to a template directory. The idea is to crawl up the tree pushing paths onto the stack as long as there are contents in ...
0
votes
0answers
28 views
Create a SelfJoin with has_many
I am trying to do a self-join. I generated this migration to make a
correct primary. This code works, but I'm not sure if this is the best way to do things.
...
5
votes
2answers
59 views
Rails API for communication between two Rails app where the former app posts data to the latter and the latter return a response
The Controller code for the first app to post data to another app
...
1
vote
0answers
19 views
Creating a list of things by looking up multiple sources
I am trying to write a rspec webmock test for a rails PORO model. What this model does is, query bugzilla with a set of filters for a list of bugs and iterate over it such that:
The bug ids are used ...
2
votes
1answer
38 views
Gem to interact with a third party API
I am writing a gem for users to interact with a third party api. I want users to have easy and natural access to objects and properties delivered by the JSON payload.
The collection of entities ...
6
votes
2answers
107 views
Another Tic Tac Toe In Ruby
I am messing with Ruby a little bit and would like to get some feedback about the Spaghettii below :)
...
5
votes
1answer
56 views
Stack class in Ruby to calculate maximum number, get the average, pop, push
Is the class optimized enough to accept 1 million items in the stack?
...
4
votes
1answer
57 views
Brainf**k interpreter in Ruby
I wrote this interpreter for a code challenge. Can this be written any cleaner/smaller? Could I reduce the amount of nested conditional/loops?
...
1
vote
1answer
47 views
Class/model hierarchy for a school-management application
Please find how I would model a system that had teachers, students, classes and parents. Instead of creating a model for each user type, I created only two models, ...
4
votes
3answers
61 views
Getting the Twitter account from various input formats
I have an input for users to enter a Twitter account in any different way and I want to extract the user account.
For example:
...
2
votes
1answer
24 views
Regex detection for Puppet configuration
I've got a PR to add a feature to a Ruby application (Puppet) to allow Regex detection.
Right now, the method only does comparison on exact string matching:
...
4
votes
1answer
35 views
Deserializer in ruby
Given a serialized hash of any depth in string format, convert it into a hash object.
I want to know if my approach is correct, I am capturing states and storing the results in a stack and generating ...
3
votes
1answer
48 views
Machi Koro card/dice game
I have taken advice on board and had a go at a new project, to write a program that lets you play the card/dice game, Machi Koro. The complexity of the game isn't too great, which makes it a good ...
3
votes
1answer
59 views
Mastermind game - Evaluating the guess in Ruby
I am a novice coder and I am very new to algorithms. Something about my code leads me to believe that it is unnecessarily verbose and/or inefficient. I am building a command line Mastermind game, and ...
-2
votes
2answers
69 views
Advice on Optimizing Ruby Code Structure
I have the current code structure which works but i feel there should be a better way of optimizing the code structure or writing it much more cleaner.
Can anyone suggest a better way to represent ...
0
votes
1answer
36 views
Validating only attributes that are present in a form [closed]
I want to skip validations based on attributes. If certain attributes are not in form so I do not want to validate them.
Currently, if I post them from one form which has 1 field, it still validates ...
2
votes
1answer
56 views
Tic Tac Toe in Ruby
I'm a novice programmer going through the Odin Project. I just finished up building a command line Tic Tac Toe game and I would appreciate some feedback on object-oriented design, methods, verbosity, ...
6
votes
1answer
53 views
Web Development DSL
I'm working on a DSL for web development, similar to sinatra. The git repository is here. I've been attempting to improve this code and write it for 4 months, and as a hobby programmer, I would like ...
-1
votes
1answer
59 views
How to run this code faster
This sample code is correct and no error however this only good if you only have few hundreds or thousand datas but if you have million queries this takes time how we can improve this algorithm
...
3
votes
2answers
89 views
Build a pizza and choose your toppings
I've created a scenario below, in which a user can build a pizza and choose their toppings, then order their pizza:
...
3
votes
1answer
57 views
Helper that swaps out some text for certain icons
I have a Rails helper that swaps out some text for certain icons.
Example:
Helper Sample
...
1
vote
0answers
55 views
Ruby - Asteroids Remake
After some feedback on my last Ruby Code I decided to start another one with two big concerns in mind:
Trying to adequate my coding to the OOP paradigm
Trying to follow the Ruby Style-Guideliness
I ...
1
vote
1answer
35 views
Finding users who liked a post
I have a method liked_by and it doesn't seem like appropriate as per Ruby style. I need to do it as less as possible.
...
-2
votes
3answers
73 views
4
votes
1answer
78 views
Countdown AppIndicator
I've decided to translate an old Unity AppIndicator I had written in C to Ruby, so I can practice coding with it (got a little bored with the completely beginner lessons I've been following, which I'...
1
vote
0answers
31 views
Service Connector abstraction for Ruby
My Rails apps need to connect to several external services to perform some functions.
Now, I realize that some of the services I need might also be reused outside Rails (like in Capistrano ...
2
votes
2answers
52 views
Fraction class with documentation
I have never worked with Ruby before, and thought I'd start working on learning it. For my first little implementation, I have created a simple fraction class. It would be nice if someone would check ...
3
votes
2answers
38 views
Ensure continuous date range
I have two arrays
dates = ["20161010","20161013"]
values = [5,3]
which represent dates and a view count. To display them in a graph, I also need the values ...
1
vote
2answers
53 views
Title capitalization exercise from The Odin Project
I just finished the book title class exercise for The Odin Project and I would appreciate some honest feedback for my code. The code is intended to be "test-driven learning", and therefore emulates ...
4
votes
1answer
71 views
Finding the indices where a selected player appears in a list of hashes
I have an array of hashes in a YAML file. When I run the code below it is VERY slow. My YAML pwsarr.count is about 2000.
I am somewhat new to Ruby so I don't know ...
4
votes
1answer
55 views
The Odin Project - Project Ruby: Translating from English to Pig Latin
I just finished the pig latin translator for The Odin Project and I would appreciate some honest feedback for my code. The code is intended to be "test-driven learning", and therefore emulates test ...
1
vote
0answers
39 views
Scoping through embedded document in MongoId
I'm using MongoId in a Rails project. I need to select some products which contain some SKUs which has an embedded document. The models are respectively Product and ...
3
votes
0answers
40 views
Achieving thread safety in a payment service library
I wrote this code a while ago, which is an excerpt of a payment service library:
...
4
votes
1answer
65 views
Marketplace checkout system
I was given the following code challenge as part of an interview process, unfortunately I did not get through to the next stage. Any advice on how I could improve would be very much appreciated.
Here ...
1
vote
1answer
41 views
Skip invalid record and avoid execution break for invalid record
Here is the pseudo code used inside a Rails controller:
...