Using a database within a Ruby gem

I’d like to use a database within a Ruby gem that I’m writing. The gem is meant to be used within Rails applications, and will contain an inverted index of documents passed in from the main Rails app. I’m a bit confused as to how to go about this. Should I hook into the main […]

Ruby: How to find item in array which has the most occurrences?

[1, 1, 1, 2, 3].mode => 1 [‘cat’, ‘dog’, ‘snake’, ‘dog’].mode => dog

Ruby max integer

I need to be able to determine a systems maximum integer in Ruby. Anybody know how, or if it’s possible?

Enums in Ruby

What’s the best way to implement the enum idiom in Ruby? I’m looking for something which I can use (almost) like the Java/C# enums.

Is there a way to know if my Ruby gem is being used?

I created a Ruby gem and I would like to know if people are using it after they download it.

ruby date difference consolidation

I am working on a project where I have to calculate the total previous expereince of an employee. So lets say an employee worked Company 1 – 11th Feb 2008 to 23rd Feb 2010 Company 2 – 14 May 2010 to 17 Oct 2014 Company 3 – 22 Dec 2014 to 14 Jan 2017 I […]

A rake task from a gem doesn't show up in a Rails application

I’m building a gem with a list of rake tasks. I have this: #/lib/tasks/my_gem.rake: namespace :my_gem do task :task1 do puts “Hello” end end I install the gem to a rails application and run rake -T. And there’s no task “task1” or anything related to “my_gem”.

What are :+ and &:+ in Ruby?

I’ve seen these several times but I can’t figure out how to use them. The pickaxe says that these are special shortcuts but I wasn’t able to find the syntactical description. I’ve seen them in such contexts: [1,2,3].inject(:+) to calculate sum for example.

Capistrano – How to not restart on deploy

My current Capistrano version is 2.15.5 Whenever I run the deploy task, it triggers a restart automatically. This is expected as per the doc. ———————————————————— cap deploy ———————————————————— Deploys your project. This calls both `update’ and `restart’. In my case, I want to manually run the restart task. I don’t want deploy to run restart. […]

Executing custom functions in Rails

I’m trying to integrate the socialization gem but I can’t get over the hump. The gem makes it super easy for models to follow and like one another (e.g. dude.follow!(otherdude)). It adds the tables behind the scenes. Works great in the console but I can’t translate it into the MVC model. All I want is […]

Ruby is the best programming language in the world - Ruby on Rails.