Tag: ruby

What does <<-CONSTANT do?

return <<-HTML <li> <a href = “some-link”>Link-Title</a> </li> HTML What are <<-HTML on the first line and HTML on the last line for?

Difference between '..' (double-dot) and '…' (triple-dot) in range generation?

I’ve just started learning Ruby and Ruby on Rails and came across validation code that uses ranges: validates_inclusion_of :age, :in => 21..99 validates_exclusion_of :age, :in => 0…21, :message => “Sorry, you must be over 21” At first I thought the difference was in the inclusion of endpoints, but in the API docs I looked into, […]

Where is Ruby's string literal juxtaposition feature officially documented?

I recently realized that if you juxtapose a sequence of Ruby string literals (e.g. ‘a’ “b” ‘c’), it’s equivalent to the concatenation of those string literals. However, I can’t find this language feature documented anywhere. I’ve searched using the terms “juxtaposition” and “concatenation”, but only found reference to it in a couple of StackOverflow responses. […]

No increment operator (++) in Ruby?

Possible Duplicate: Why doesn't Ruby support i++ or i— for fixnum? Why is there no increment operator in Ruby? e.g. i++ ++i Is the ++ operator used for something else? Is there a real reason for this?

Is it possible to get Ruby syntax highlighting in PHPStorm?

I found this but honestly not sure how to install it or whether it applies. Thanks!

Array slicing in Ruby: looking for explanation for illogical behaviour (taken from Rubykoans.com)

I was going through the exercises in Ruby Koans and I was struck by the following Ruby quirk that I found really unexplainable: array = [:peanut, :butter, :and, :jelly] array[0] #=> :peanut #OK! array[0,1] #=> [:peanut] #OK! array[0,2] #=> [:peanut, :butter] #OK! array[0,0] #=> [] #OK! array[2] #=> :and #OK! array[2,2] #=> [:and, :jelly] #OK! […]

Ruby: How to set feedjira configuration options?

In the Feedjira 2.0 announcement blog post, it says that if you want to set the user agent, that should be a configuration option, but it is not clear how to do this. Ideally, I would like to mimic the options previously provided in Feedjira 1.0, including user_agent, if_modified_since, timeout, and ssl_verify_peer. http://feedjira.com/blog/2014/04/14/thoughts-on-version-two-point-oh.html With Feedjira […]

Mixing keyword with regular arguments in Ruby?

Ruby 2.0 supports keyword arguments. I was wondering, what are the ‘rules’ for mixing regular with keyword arguments? Something like this would not work: def some_method(a: ‘first’, b: ‘second’, c) [a, b, c] end but this will: def some_method(c, a: ‘first’, b: ‘second’) [a, b, c] end So why does putting a regular argument before […]

paperclip-dropbox gem throws wrong argument type

I’m trying to use the paperclip-dropbox gem here, and I’m having issues with the setup and passing my credentials. In the documentation, the setup in the model is done like so: class User < ActiveRecord::Base has_attached_file :avatar, :storage => :dropbox, :dropbox_credentials => “#{Rails.root}/config/dropbox.yml”, :dropbox_options => {…} end I have configured my dropbox.yml file and put […]

Why is this RMagick call generating a segmentation fault?

I’ve been banging my head against the wall for the better part of an hour trying to figure out what’s going wrong here, and I’m sure (or rather hoping) it’s something fairly obvious that I’m overlooking. I’m using Ruby 1.9.1, Sinatra 1.0, and RMagick 2.13.1. ImageMagick and RMagick are correctly installed and functional—I’ve successfully manipulated […]

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