ruby-1.9.2

Using Ruby 1.9.2 with RubyMine and Matrix

不问归期 提交于 2019-12-11 11:06:38
问题 I am using ruby 1.9.2-p290 and RubyMine. And i try to use Matrix (require 'matrix'). So, i have few questions. How can i change any value of matrix? For example: require 'matrix' matrix = Matrix[[1, -2, 3], [3, 4, -5], [2, 4, 1]] matrix[0, 0] = 5 p matrix Gives next: in `<top (required)>': private method `[]=' called for Matrix[[1, -2, 3], [3, 4, -5], [2, 4, 1]]:Matrix (NoMethodError) from -e:1:in `load' from -e:1:in `<main>' Is it possible to show me methods for matrix by code completion in

Ruby IO.popen with “-” , what happens under the hood?

折月煮酒 提交于 2019-12-11 01:43:14
问题 I'm trying to understand IO.popen when its command is "-" which starts a new Ruby interpreter. There is not much material about this subject, and I'm getting slowly through them, mainly because of me as I only code for fun. As far as I have understood when IO.popen("-", "w+") {|f| ...} is invoked - that's with a block - that block will be run by both the parent and the child process. The difference is that the parent process will get an IO object as a result, but the child gets only a Nil.

Why is YAML.load returning the wrong numeric value?

☆樱花仙子☆ 提交于 2019-12-10 21:51:50
问题 Why is YAML.load returning the wrong value? ruby-1.9.2-p0 :006 > a = YAML.load('merchant_id: 014213245611111') => {"merchant_id"=>843333440073} ruby-1.9.2-p0 :007 > a["merchant_id"] => 843333440073 I'm on ruby 1.9.2-p0, rvm, ubuntu10.10, 64bit. 回答1: The YAML parser is treating "014213245611111" as an octal (base-8) number, rather than a string. Wrap it in quotes to preserve the leading 0. 回答2: A leading 0 signifies an octal number — 14213245611111 octal == 843333440073 decimal. If you need to

Why am I not able to install Ruby 1.9.2 on Mac OSX Lion? [closed]

吃可爱长大的小学妹 提交于 2019-12-10 17:10:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago . I am trying to install Ruby 1.9.2 on a brand new MacBook Air with OSX Lion (10.7.2) and I keep getting an error message during the installation process. I'm new to Ruby and starting out with Ruby on Rails 3 Tutorial, so I downloaded RVM and then ran the command "$ rvm install 1.9.2." and this is what happened:

Ruby 1.9.2 export a CSV string without generating a file

给你一囗甜甜゛ 提交于 2019-12-10 12:44:42
问题 I just can't get the 'To a String' example under 'Writing' example in the documentation to work at all. ruby -v returns: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0] The example from the documentation I can't working is here: csv_string = CSV.generate do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] end The error I get is: wrong number of arguments (0 for 1) So it seems like I am missing an argument, in the documentation here it states: This method

Constant Lookup with instance_eval in Ruby 1.9

大憨熊 提交于 2019-12-10 10:24:57
问题 The Short and Sweet Running this code in Ruby 1.9: FOO = "global constant" class Something FOO = "success!" def self.handle &block self.new.instance_eval &block end end class Other FOO = "wrong constant" def self.handle Something.handle{FOO} end end puts Something.handle{FOO} puts Other.handle I get "success!" and "wrong constant". How can I get both calls to print "success!"? This is not a contrived exercise for fun - I wouldn't waste people's time for that. I have a real-world problem, and

How do I “force” my Rails 3 app to use 1.9.2

主宰稳场 提交于 2019-12-08 06:07:17
问题 I have setup Rails 3.0.3 and installed Ruby 1.9.2 with rvm and set rvm to use 1.9.2 by default. However, when I create a new rails app and check the environmental variables it still reflects ruby 1.8.7, how do I update this to 1.9.2? 回答1: You are probably executing an old 1.8.7 rails binary that is being found first in your UNIX search path. You can type which rails at the command line to see which rails executable you are running. On my machine I get: /Users/scott/.rvm/gems/ruby-1.9.2-p136

capybara - Find with xPath is leaving the within scope

依然范特西╮ 提交于 2019-12-06 20:33:45
问题 I am trying to build a date selector with Capybara using the default Rails date, time, and datetime fields. I am using the within method to find the select boxes for the field but when I use xPath to find the correct box it leaves the within scope and find the first occurrence on the page of the element. Here is the code I am using. The page I am testing on has 2 datetime fields but I can only get it to change the first because of this error. At the moment I have an div container with id that

Whenever gem won't update crontab tasks

女生的网名这么多〃 提交于 2019-12-06 05:29:18
问题 I have been using the whenever gem on my 2+ year old slice at Slicehost. I can't however do the same on my new slice. Main differences is that I'm now running RVM on both my MBP and the slice. I am also running Rails 3. I've got Rubygems v 1.5.0 and latest versions of RVM , Ruby 1.9.2p136, Capistrano and about every other package out there. I have tried a million things, read all the docs and as of now I'm using the whenever gem version 0.6.2. I have also looked at all questions on related

Extract the AST from a Ruby block

 ̄綄美尐妖づ 提交于 2019-12-05 22:44:26
问题 Is it possible to grab the AST of a block from Ruby itself? I've had a look at both ParseTree and ruby_parser, but they both seem to have sketchy support (from what I've read) for Ruby 1.9.2. I need something that works well with 1.9.2. 回答1: Ripper is included in MRI 1.9 out of the box. ruby-1.9.2-p180 :004 > require 'ripper' => true ruby-1.9.2-p180 :005 > Ripper.sexp("def a; end") => [:program, [[:def, [:@ident, "a", [1, 4]], [:params, nil, nil, nil, nil, nil], [:bodystmt, [[:void_stmt]],