ruby-1.9

ruby require not working

南楼画角 提交于 2019-12-25 05:21:06
问题 I'm new to ruby, but I'm working on my first ruby program. It currently has two files, one is a library of functions ( xgync.rb stored in lib ) the other is the executable xgync stored in 'bin'. (Project visible here https://bitbucket.org/jeffreycwitt/xgync/src) I've also created a symlink to my /usr/local/bin/xgync so that I can write the command xgync {arguments} from anywhere in the terminal. The problem seems to be that bin/xgync depends on the library lib/xgync.rb . I've written this

Can't install ruby 1.9.1 on MacOSX 10.6

ε祈祈猫儿з 提交于 2019-12-25 03:37:27
问题 I can't seem to be get Ruby installed on my Mac. These are the steps I've taken so far: Downloaded the package from Ruby's site (http://www.ruby-lang.org/en/downloads/) Unpacked it running { tar xzvf ruby-1.9.1-p376.tar.gz } Went into the new ruby folder, and configured using {./configure} This is where the error happens. When I run the configure, it gives me the error: /usr/local/include/fuse/fuse_common.h:32:2: error: #error Please add -D_FILE_OFFSET_BITS=64 to your compile flags! In file

Errors from `ObjectSpace._id2ref`

回眸只為那壹抹淺笑 提交于 2019-12-24 01:01:27
问题 What is the difference between the following two kinds of errors that ObjectSpace._id2ref returns? 0x... is recycled object (RangeError) 0x... is not id value (RangeError) 回答1: not id value means that there never was an object with that id. recycled object means that there once was an object with that id, but it has been garbage collected. Demo on Ruby 1.9.3/Ubuntu: x = Object.new id = x.object_id puts "0x%x" % id # => 0x4aef5e8 puts ObjectSpace._id2ref id # => #<Object:0x95debd0> x = nil

How do I replace all the values in a hash with a new value?

最后都变了- 提交于 2019-12-23 20:37:10
问题 Let's say I have an arbitrarily deep nested Hash h : h = { :foo => { :bar => 1 }, :baz => 10, :quux => { :swozz => {:muux => 1000}, :grimel => 200 } # ... } And let's say I have a class C defined as: class C attr_accessor :dict end How do I replace all nested values in h so that they are now C instances with the dict attribute set to that value? For instance, in the above example, I'd expect to have something like: h = { :foo => <C @dict={:bar => 1}>, :baz => 10, :quux => <C @dict={:swozz =>

Splat on a hash

最后都变了- 提交于 2019-12-23 07:26:38
问题 A splat on a hash converts it into an array. [*{foo: :bar}] # => [[:foo, :bar]] Is there some hidden mechanism (such as implicit class cast) going on here, or is it a built-in primitive feature? Besides an array, are nil and hash the only things that disappear/change with the splat operator under Ruby 1.9? 回答1: A splat will attempt an explicit conversion of an object to an Array. To do this, it will send to_a and expect an Array as a result. class Foo def to_a [1,2,3] end end a, b, c = *Foo

Is there a way to call ruby1.9 without loading rubygems?

淺唱寂寞╮ 提交于 2019-12-22 04:33:16
问题 So ruby 1.9 is really nice in that it'll automatically require rubygems, and hence when you call require 'somegem' without first requiring rubygems it'll work, and that's generally awesome. But I have a ton of shell scripts using ruby, and they generally don't rely on rubygems. Shell tools should run instantly, and loading rubygems for nothing is a major drag, mostly because it involves a bunch of disk operations with scattered small files. I want to be able to tell ruby, when running these

ruby CSV duplicate row parsing

亡梦爱人 提交于 2019-12-21 20:39:33
问题 I have some CSV data I need to process, and having trouble figuring out a way to match the duplicates. data looks a bit like this: line id name item_1 item_2 item_3 item_4 1 251 john foo foo foo foo 2 251 john foo bar bar bar 3 251 john foo bar baz baz 4 251 john foo bar baz pat lines 1-3 are duplicates in this case. line id name item_1 item_2 item_3 item_4 5 347 bill foo foo foo foo 6 347 bill foo bar bar bar in this case only line 5 is a duplicate line id name item_1 item_2 item_3 item_4 7

How can I match Korean characters in a Ruby regular expression?

岁酱吖の 提交于 2019-12-21 17:39:09
问题 I have some basic validations for usernames using regular expressions, something like [\w-_]+ , and I want to add support for Korean alphabet, while still keeping the validation the same. I don't want to allow special characters, such as {}[]!@#$%^&*() etc., I just want to replace the \w with something that matches a given alphabet in addition to [a-zA-Z0-9] . Which means username like 안녕 should be valid, but not 안녕[] . I need to do this in Ruby 1.9. 回答1: You can test for invalid characters

What are Ruby's numbered global variables

[亡魂溺海] 提交于 2019-12-21 04:12:57
问题 What do the values $1, $2, $', $` mean in Ruby? 回答1: They're captures from the most recent pattern match (just as in Perl; Ruby initially lifted a lot of syntax from Perl, although it's largely gotten over it by now :). $1 , $2 , etc. refer to parenthesized captures within a regex: given /a(.)b(.)c/ , $1 will be the character between a and b and $2 the character between b and c . $` and $' mean the strings before and after the string that matched the entire regex (which is itself in $& ),

How do Enumerators work in Ruby 1.9.1?

允我心安 提交于 2019-12-20 21:00:16
问题 This question is not about how to use Enumerators in Ruby 1.9.1 but rather I am curious how they work. Here is some code: class Bunk def initialize @h = [*1..100] end def each if !block_given? enum_for(:each) else 0.upto(@h.length) { |i| yield @h[i] } end end end In the above code I can use e = Bunk.new.each , and then e.next , e.next to get each successive element, but how exactly is it suspending execution and then resuming at the right spot? I am aware that if the yield in the 0.upto is