class << self idiom in Ruby

What does class << self do in Ruby?

How does object_id assignment work?

I’m playing around with Ruby’s .object_id and noticed that, in several sequential sessions of irb, I get these identical results: false.object_id // 0 true.object_id // 2 nil.object_id // 4 100.object_id // 201 In fact, every integer’s object_id seems to be ((value * 2) + 1). On the other hand, a given string’s object_id is never […]

How do I debug Ruby scripts?

I copied the following Ruby code from the Internet and made a few changes. #insert code here But it doesn’t work! Please help. What can I do to debug the program by myself?

How to create a file in Ruby

I’m trying to create a new file and things don’t seem to be working as I expect them too. Here’s what I’ve tried: “out.txt” “out.txt” “out.txt”,”w” “out.txt”,”w” According to everything I’ve read online all of those should work but every single one of them gives me this: ERRNO::ENOENT: No such file […]

Is 'eval' supposed to be nasty?

I have been using eval feature of ruby many a times. But I have heard people saying evals are nasty. When asked, why and how, I could never get a convincing reason not to use it. Are they really nasty? If yes, in what way? What are possible “safer” options to eval?

cannot load such file — script/rails : Getting this error while remote debugging through RubyMine

I am getting following error while remote debugging through RubyMine IDE. $ bundle exec rdebug-ide –port 1234 — script/rails server Fast Debugger (ruby-debug-ide 0.4.9) listens on :1234 /home/amit/.rvm/gems/ruby-1.9.3-p125/gems/ruby-debug-ide19-0.4.12/lib/ruby-debug-ide.rb:123:in `debug_load’ /home/amit/.rvm/gems/ruby-1.9.3-p125/gems/ruby-debug-ide19-0.4.12/lib/ruby-debug-ide.rb:123:in `debug_program’ /home/amit/.rvm/gems/ruby-1.9.3-p125/gems/ruby-debug-ide19-0.4.12/bin/rdebug-ide:87:in `<top (required)>’ /home/amit/.rvm/gems/ruby-1.9.3-p125/bin/rdebug-ide:19:in `load’ /home/amit/.rvm/gems/ruby-1.9.3-p125/bin/rdebug-ide:19:in `<main>’ Uncaught exception: cannot load such file — script/rails I followed this link to install require gems for […]

Converting a nested hash into a flat hash

This question is the inverse of this question. Given a nested hash like { :a => { :b => {:c => 1, :d => 2}, :e => 3, }, :f => 4, } what is the best way to convert it into a flat hash like { [:a, :b, :c] => 1, [:a, :b, :d] […]

Can't find my ruby gems

I have been using gems fine. I use compass watch to map changes to my scss files to css files. I hadn’t used it for a week. I tried doing compass watch, and now its telling me compass isn’t installed. I did a gem list command and I only have six gems locally now. I […]

Best way to categorize products in rails 4 app

So, I’m trying to create a product categorization ‘system’ in my rails 4 app. Here’s what I have so far: class Category < ActiveRecord::Base has_many :products, through: :categorizations has_many :categorizations end class Product < ActiveRecord::Base include ActionView::Helpers has_many :categories, through: :categorizations has_many :categorizations end class Categorization < ActiveRecord::Base belongs_to :category belongs_to :product end Also, what […]

image not showing if there is a space between image name in rails with carrierwave

I am using carrierwave gem to upload images in rails. But my images are not showing in a slider if there a space between image name. Any help?

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