What are the magic $-prefixed variables in Ruby? [closed]

Their name is global variables. There are several different references. You can get a full list by calling the method Kernel#global_variables puts global_variables Ruby also includes a file called “English.rb” in the standard library which provides an in-depth explanation of several global variables. Also, there’s (an archived version of) “Cryptic Ruby Global Variables and Their … Read more

Ruby Select and Reject in one method

Looks as if Enumerable.partition is exactly what you are after. = Enumerable.partition (from ruby core) —————————————————————————— enum.partition {| obj | block } -> [ true_array, false_array ] enum.partition -> an_enumerator —————————————————————————— Returns two arrays, the first containing the elements of enum for which the block evaluates to true, the second containing the rest. If no … Read more

Ruby – Module :: NoMethodError

Apart from the answers that give you the option of defining the function as self., you have another option of including the module and calling it without the module reference like this: module Prober def probe_invoke(type, data = {}) p = Probe.new({:probe_type => type.to_s, :data => data.to_json, :probe_status => 0, :retries => 0}) p.save end … Read more

How can I install Ruby 1.9.3 in Mac OS X Mountain Lion without Xcode?

osx-gcc-installer turns out to be a very good option to replace Xcode in order to install Ruby 1.9.3 These are the steps I have followed: Download & install the latest version of osx-gcc-installer here (GCC-10.7-v2 is fine): https://github.com/kennethreitz/osx-gcc-installer Install RVM as usual and select 1.9.3-head as the default ruby installation: https://rvm.io/rvm/install/ Install Homebrew: https://github.com/mxcl/homebrew/wiki/installation Install … Read more

Ruby .ceil and .floor

Everything is returned correctly. puts 8/3.ceil == 2 #=> true, because 8/3 returns an Integer, 2 puts 8/3.floor == 2 #=> true, because 8/3 returns an Integer, 2 puts 2.67.ceil == 2 #=> false, because 2.67.ceil is 3 puts 2.67.floor == 2 #=> true, because 2.67.floor is 2 To make things of more sense here, … Read more

How to read POST data in rack request

From reading the docs for POST, looks like it is giving you parsed data based on other content types. If you want to process “application/json”, you probably need to JSON.parse( req.body.read ) instead. To check this, try puts req.body.read where you currently have puts req.POST. req.body is an I/O object, not a string. See the … Read more

Getting typed results from ActiveRecord raw SQL

While I have no doubt that Björn Nilsson’s answer worked when he posted it, it is failing for me with Postgres 9.4 and PG gem version 0.18.2. I have found the following to work after looking through the PG gem documentation: pg = ActiveRecord::Base.connection @type_map ||= PG::BasicTypeMapForResults.new(pg.raw_connection) res = pg.execute(“SELECT ‘abc’::TEXT AS a, 123::INTEGER AS … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)