ruby-1.9

Globbing using braces on Ruby 1.9.3

随声附和 提交于 2019-12-12 08:33:16
问题 Recent versions of Ruby support the use of braces in globbing, if you use the File::FNM_EXTGLOB option From the 2.2.0 documentation File.fnmatch('c{at,ub}s', 'cats', File::FNM_EXTGLOB) #=> true # { } is supported on FNM_EXTGLOB However, the 1.9.3 documentation says it isn't supported in 1.9.3: File.fnmatch('c{at,ub}s', 'cats') #=> false # { } isn't supported (also, trying to use File::FNM_EXTGLOB gave a name error) Is there any way to glob using braces in Ruby 1.9.3, such as a third-party gem

How to test background process in RSpec?

痴心易碎 提交于 2019-12-12 04:33:37
问题 Found this simple way to run a separate process in Sinatra: Run background process in Sinatra get '/start_process' @@pid = Process.spawn('external_command_to_run') end How would you test this in RSpec? Ruby 1.9.3. 回答1: Extract a class which does the background processing and unit-test it. Then test expectation that your action invokes method on this class Some "pseudocode": before do MyWorker.should_receive(:perform) end specify { get :something } 来源: https://stackoverflow.com/questions

Why does the ?a command in ruby 1.9.2 does not return ASCII code

两盒软妹~` 提交于 2019-12-11 09:24:02
问题 When you do ?a in ruby 1.8.7 you used to get the ASCII character of 'a' in ruby 1.9.2 this code returns > ?a > "a" What is the significance of this, and what does the output in 1.9.2 mean 回答1: In Ruby 1.8 "foo"[0] returned the character code at index 0 instead of the character string at index 0. As part of support for international strings with various encodings (instead of as an array of bytes), Ruby 1.9 changed this behavior to return the single-character string at the specified index.

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

Active Directory LDAP move user to different OU - Ruby

心不动则不痛 提交于 2019-12-10 17:08:41
问题 I have hit a snag in my integration with Active Directory. I need to be able to move users from one OU to another. I'm using net-ldap 0.5.0 which is on github master branch and dug around in the source code and found out you could do this $ldap.rename( olddn: "cn=bradford ricechip,ou=agents,ou=ihs,ou=test environment,dc=ctatechs,dc=com", newrdn: "cn=bradford ricechip", new_superior: "ou=coach,ou=ihs,ou=test environment,dc=ctatechs,dc=com" ) I'm getting: #<OpenStruct code=53, error_message=

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

Error 'incompatible character encodings: ASCII-8BIT and UTF-8' due to 8-bit encoding of cookies (Rails 3 and Ruby 1.9)

我与影子孤独终老i 提交于 2019-12-10 03:56:35
问题 I moved a web app that was using 1.8.7 to 1.9.2 and now I keep getting incompatible character encodings: ASCII-8BIT and UTF-8 I have the database encoding to UTF-8 and I have also 'config.encoding = "utf-8"'. I saw some ideas as possible workarounds and I added Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 But it didn't work either. One specific chunk of code where I am getting this error is %ul.address - @user.address.split(',').each do |line| %li=

What happened with Ruby 1.9.2?

佐手、 提交于 2019-12-10 00:25:05
问题 I have seen that there is no updates for Ruby 1.9.2. (Only for Ruby 1.9.3 & 2.0). My question is: what happened with 1.9.2? I'm confused if 1.9.3 and 1.9.2 are different branches, or 1.9.3 is the sequel, and if my 1.9.2 app will works with 1.9.3 without problems. 回答1: If you're talking about updates to deal with CVE-2013-4073, then Ruby-lang.org says: All users are recommended to upgrade to Ruby 2.0.0-p247, 1.9.3-p448 or 1.8.7-p374. Presumably, anyone using MRI Ruby 1.9.2 is able to use MRI

Ruby 1.9.1-p234, Passenger 2.2.5, Rails 2.3-stable closed stream on POST request

最后都变了- 提交于 2019-12-09 15:59:01
问题 I've setup Ruby 1.9.1 (p234) on a Ubuntu server. I'm trying to deploy a Rails app which vendors Rails 2.3-stable on Apache 2.2/Passenger 2.2.5. GET requests work fine, POST requests break immediately with the following log entry: Processing UsersController#new (for 80.203.77.44 at 2009-10-24 20:54:55) [GET] Parameters: {"controller"=>"users", "action"=>"new"} Rendering template within layouts/application Rendering users/new Completed in 23ms (View: 20, DB: 0) | 200 OK [ http://myapp/user/new]

Implicit argument passing of super from method defined by define_method() is not supported

醉酒当歌 提交于 2019-12-09 14:47:51
问题 In " Agile Web Development with Rails " (third edition) page 537 - 541 it has "Custom Form Builders" code as follows: class TaggedBuilder < ActionView::Helpers::FormBuilder # <p> # <label for="product_description">Description</label><br/> # <%= form.text_area 'description' %> #</p> def self.create_tagged_field(method_name) define_method(method_name) do |label, *args| @template.content_tag("p" , @template.content_tag("label" , label.to_s.humanize, :for => "#{@object_name}_#{label}") + "<br/>"