FAQ Database Discussion Community


Function overloading in Ruby [duplicate]

ruby,ruby-2.2
This question already has an answer here: Why doesn't ruby support method overloading? 6 answers I have this piece of code in Ruby. class Superheros class<<self def foo1(param1) print "foo1 got executed\n" end def foo1 print "foo1 without param got executed\n" end def foo3(param1,param2) print "foo3 got executed\n" end...

is The Ruby Programming Language book still valid in ruby 2.2.2?

ruby,ruby-2.2
I am learning ruby. I was wondering if the The Ruby Programming Language book is still valid in ruby 2.2.2 even though the book is written for ruby 1.8 and 1.9?

Check and select the latest one from the array of hashes

ruby-on-rails,ruby,ruby-2.0,ruby-2.2
I have to check and select the latest one from the array of hashes. The structure is like this: 'histories':[ { { ... }, 'created': "date1", 'items':[ { 'a': "Ready", 'b': "dfknsknfs", }, { 'a': "sdfjbsf", 'b': "hello23", } ] }, { { ... }, 'created': "date2", 'items':[ { 'a':...

How to test SSH connection using Ruby

ruby,ssh,ruby-2.2
This is what I got so far. This works great, the problem being I can't input a password for the ssh login, I need to have shared ssh keys in order for this to work: def ssh_conn(user, host, &block) begin ping_output = [] timeout(20) do ping_output = IO.popen("ssh #{user}@#{host} 'echo...

How do I add named parameters in a subclass or change their default in Ruby 2.2?

ruby,ruby-2.2
This question is about Ruby 2.2. Let's say I have a method which takes positional and named arguments. class Parent def foo(positional, named1: "parent", named2: "parent") puts positional.inspect puts named1.inspect puts named2.inspect end end A subclass wants to both override some defaults, and add its own named arguments. How would...

ruby on rails AbstractController::Helpers::MissingHelperError: Missing helper file helpers//

ruby-on-rails,ruby,ruby-on-rails-4,ruby-2.2
I just cloned a repository I was working on from another computer. When I try to do a database migration by running 'rake db:migrate' I get the following error: AbstractController::Helpers::MissingHelperError: Missing helper file helpers//users/psmith/projects/clie/projectlion/app/helpers/application_helper.rb_helper.rb I have already tried the top answer here: Rails: AbstractController::Helpers::MissingHelperError - Missing helper file application_helper.rb_helper.rb It...

Active Record Query to select an entry, that does not already have a vote that I have already given

ruby-on-rails,activerecord,ruby-on-rails-4.2,ruby-2.2
I have the following three models Judge (Devise User) Judge.column_names => ["id", "email", "encrypted_password", "reset_password_token", "reset_password_sent_at", "remember_created_at", "sign_in_count", "current_sign_in_at", "last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip", "created_at", "updated_at", "confirmation_token", "confirmed_at", "confirmation_sent_at", "unconfirmed_email"] class Judge < ActiveRecord::Base has_many :votes end Entry Entry.column_names => ["id", "entrant_id", "title_of_work", "price",...

DateTime subtraction in ruby 2?

ruby,datetime,ruby-2.2
I need to subtract two DateTime objects in order to find out the difference in hours between them. I try to do the following: a = DateTime.new(2015, 6, 20, 16) b = DateTime.new(2015, 6, 21, 16) puts a - b I get (-1/1), the object of class Rational. So, the...

How to restrict user to search for a particular model in view?

ruby-on-rails,ruby-on-rails-4.2,cancancan,ruby-2.2
Application I am working has different user roles client, project manager and super user and on landing page they can search for Articles and there is an advanced filter to filter out records after search. Like: Filter by Author. I want to hide advance filter for client, for that i...

Ruby JSON Multi-Word Strings Rendered Incorrectly in HTML

html,ruby,json,ruby-on-rails-4,ruby-2.2
My multi-word strings aren't being interpreted correctly in the DOM. How can I ensure JSON integrity from server to HTML with multi-word strings? In the Rails controller, I store a JSON object in a variable. That object is correctly formatted when I check in the server logs. That variable is...

ruby `stack level too deep error` when trying to user order param

ruby-on-rails,ruby,kaminari,ruby-2.2,rails-4-2-1
I'm trying to add a sort_by params to a rails app that uses Kaminari for paging. When add the param to the query I get a stack level too deep error. app/controllers/file_items_controller.rb class FileItemsController < AccountsController def index account = Account.includes(:credentials).find params[:account_id] @page = page_param.to_i @tab = 'Files' @credential =...

Error installing Ruby 2.2.2 with RVM on Ubuntu 14.04

ruby,rvm,ubuntu-14.04,ruby-2.2
Here's what. I first did: rvm get stable rvm install ruby-2.2.2 No deal. It shows me the following: $ rvm install ruby-2.2.2 Searching for binary rubies, this might take some time. No binary rubies available for: ubuntu/14.04/i386/ruby-2.2.2. Continuing with compilation. Please read 'rvm help mount' to get more information on...

How to run existing test code on Ruby 2.2

ruby,minitest,ruby-2.2
The following code (which has no Gemfile) works on Ruby 2.1.1, but not Ruby 2.2.0 require "bundler/setup" gem "minitest", "4.7.5" require "test/unit" class TestFoo < Test::Unit::TestCase def test_foo assert true, "Useless mesage" skip "Skip works" end end On Ruby 2.1.1, I get Run options: # Running tests: [1/1] TestFoo#test_foo =...