ruby-1.9

Where are methods defined at the ruby top level?

瘦欲@ 提交于 2019-11-28 23:25:34
问题 At the top level, method definition should result in private methods on Object , and tests seem to bear this out: def hello; "hello world"; end Object.private_instance_methods.include?(:hello) #=> true Object.new.send(:hello) #=> "hello world" However, the following also works at top level ( self.meta is the eigenclass of main ): self.meta.private_instance_methods(false).include?(:hello) #=> true It appears that the hello method is simultaneously defined on the eigenclass of main as well as

How to specify output file encoding in Ruby?

天涯浪子 提交于 2019-11-28 22:29:55
How can I set the encoding of a file when using a File#open ? Here's an example that outputs a file in the UTF-16LE encoding: open("data.txt", "w:UTF-16LE") Ruby looks at the encoding of the string you are writing, and transcodes as necessary. Here's a very detailed blog post describing mechanics with excellent examples (see the section called "The Default External and Internal Encodings"). That blog also has a bunch of great information about character encoding with Ruby, including a post about encoding with Ruby 1.8 . Here's the way to read pages with Japanese Shift JIS encoding: file = open

How to replace the Unicode gem on Ruby 1.9?

≯℡__Kan透↙ 提交于 2019-11-28 19:57:34
Unfortunately, the Unicode 0.1 ( sudo gem install unicode ) doesn't work on Ruby 1.9. I have the following snippet: require "rubygems" require "unicode" str = "áéíóúç" Unicode.normalize_KD(str).gsub(/[^\x00-\x7F]/n, "") #=> aeiouc I use it to convert titles to permalink, without removing accented characters. Is there a way of converting such texts using pack or unpack methods? molf Update: a better option may be to use the gem unicode_utils that was created specifically for these missing features: require "unicode_utils" UnicodeUtils.nfkd("áéíóúç").gsub(/[^\x00-\x7F]/,'').to_s #=> "aeiouc" Is

write csv in ruby 1.9 and CSV::Writer

心已入冬 提交于 2019-11-28 19:31:09
i have a code that works fine with ruby 1.87 but dont works with ruby 1.9. It says that CSV::Writer is undeclared but it still part of the rdoc. Does the csv api changed, after the fastercsv merge, or not? my code: require 'csv' def self.export_csv file_name = File.join(RAILS_ROOT, 'public','csv',"#{start_date_f}_#{end_date_f}.csv") return file_name if File.exist?(file_name) @results = find(:all) header_row = [] outfile = File.open(file_name, 'wb') CSV::Writer.generate(outfile) do |csv| header_row = ['gateway_id','created', 'gateway_status_id', 'panel_id', 'panel_status','volts_out', 'amps_out

How can I avoid putting the magic encoding comment on top of every UTF-8 file in Ruby 1.9?

孤街醉人 提交于 2019-11-28 18:37:58
I have a Rails project with a lot of Cyrillic strings in it. It worked fine on Ruby 1.8, but Ruby 1.9 assumes source files are US-ASCII-encoded unless you provide an # encoding: utf-8 comment at the top of the source file. At that point the files are not considered US-ASCII . Is there a simpler way to tell Ruby "This application is UTF8-encoded. Please consider all and any included source files as UTF8 unless declared otherwise"? UPDATE: I wrote " How to insert the encoding: UTF-8 directive automatically in Ruby 1.9 files " which appends the encoding directive automatically if it's needed.

Can I set the default string encoding on Ruby 1.9?

女生的网名这么多〃 提交于 2019-11-28 18:23:13
This might sound minor, but it's been driving me nuts. Since releasing an application to production last Friday on Ruby 1.9, I've been having lots of minor exceptions related to character encodings. Almost all of it is some variation on: Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8 We have an international user base so plenty of names contain umlauts, etc. If I fix the templates to use force_encoding in a bunch of places, it pops up in the flash message helper. Et cetera. At the moment it looks like I've nailed down all the ones I knew about, by patching

What's the difference between Process.fork and Process.spawn in Ruby 1.9.2

扶醉桌前 提交于 2019-11-28 16:51:37
What's the difference between Process.fork and the new Process.spawn methods in Ruby 1.9.2 and which one is better to run another program in a subprocess? As far as I understand Process.fork accepts block of code and Process.spawn takes a system command plus some other parameters. When I should use one instead of the other? What's the difference between Process.fork and the new Process.spawn methods in Ruby 1.9.2 Process.fork allows you to run ruby code in another process. Process.spawn allows you to run another program in another process. Basically Process.spawn is like using Process.fork and

Has anyone successfully deployed a Rails project with Ruby 1.9.1? [closed]

故事扮演 提交于 2019-11-28 09:19:05
Last week I successfully completed the transition of all our company applications from Ruby 1.8.6 to Ruby 1.8.7 including local and remote configurations. From now on, development won't need to ensure backward-compatibility with Ruby 1.8.6. For the sake of curiosity, I tried to run the test suite of a couple of projects against Ruby 1.9.1. As expected, I found some encoding-related issue but I was really shocked when I discovered low-level incompatibilities such as a Rack::Link known bug. At this point, the idea of moving development to Ruby 1.9.1 is simply not applicable. I was wondering if

HTML tidy/cleaning in Ruby 1.9

喜欢而已 提交于 2019-11-28 07:47:15
I'm currently using the RubyTidy Ruby bindings for HTML tidy to make sure HTML I receive is well-formed. Currently this library is the only thing holding me back from getting a Rails application on Ruby 1.9. Are there any alternative libraries out there that will tidy up chunks of HTML on Ruby 1.9? http://github.com/libc/tidy_ffi/blob/master/README.rdoc works with ruby 1.9 (latest version) If you are working on windows, you need to set the library_path eg require 'tidy_ffi' TidyFFI.library_path = 'lib\\tidy\\bin\\tidy.dll' tidy = TidyFFI::Tidy.new('test') puts tidy.clean (It uses the same dll

Why does Ruby 1.9.2 blow up with a JSON gem dependency?

≡放荡痞女 提交于 2019-11-28 07:27:17
I am having issues with the JSON gem and Ruby 1.9.2. I am upgrading to Rails 3.0.3 and whenever I try to boot the environment it blows up. This is from a empty test project with only JSON gem 1.4.6 as a dependency. /Users/lee/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/common.rb:66: [BUG] unknown type 0x22 (0xc given) ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0] -- control frame ---------- c:0032 p:---- s:0096 b:0096 l:000095 d:000095 CFUNC :initialize c:0031 p:---- s:0094 b:0094 l:000093 d:000093 CFUNC :new c:0030 p:0085 s:0091 b:0089 l:000088 d:000088 METHOD /Users/lee