yarv

How to generate bytecode in Ruby 1.9?

一个人想着一个人 提交于 2019-12-24 05:49:10
问题 How can I generate byetcode from Ruby 1.9?? My intent is to generate bytecode not the source code and ship it along with my application package. I am aware of the JRuby approach but I am facing certain issues there 回答1: Call BCEL library from JRuby. BCEL library is shipped with JDK. 来源: https://stackoverflow.com/questions/4014016/how-to-generate-bytecode-in-ruby-1-9

RVM 1.9.1 & nokogiri

依然范特西╮ 提交于 2019-12-08 17:34:07
问题 Having trouble installing the nokogiri gem under rvm ruby 1.9.1. gem install nokogiri I'm getting ... /usr/include/libxml2... no libxml2 is missing. try 'port install libxml2' or 'yum install libxml2-devel' *** extconf.rb failed *** but i checked: sudo apt-get install libxml2 and i got: Reading state information... Done libxml2 is already the newest version. is this a root thing perhaps? RVM runs everything in userspace. 回答1: You might want to confirm that the version of libxml installed by

Ruby 2.0 Bytecode Export / Import

大兔子大兔子 提交于 2019-12-04 18:17:26
问题 I've been reading about the new ruby 2.0 features, and found that it will support bytecode import / export: Ruby 2.0 is expected to make it simple to save pre-compiled Ruby scripts to bytecode representations and to then run these directly. I've installed ruby-2.0.0-p0, but I didn't find any information on how to export the bytecode (or generally documentation on that matter). Is this feature already implemented, and if so, how do I use it? I'm also wondering about some of the details. Is

Why is a Regexp object considered to be “falsy” in Ruby?

纵饮孤独 提交于 2019-12-04 10:15:45
问题 Ruby has a universal idea of " truthiness " and " falsiness ". Ruby does have two specific classes for Boolean objects, TrueClass and FalseClass, with singleton instances denoted by the special variables true and false , respectively. However, truthiness and falsiness are not limited to instances of those two classes, the concept is universal and applies to every single object in Ruby. Every object is either truthy or falsy . The rules are very simple. In particular, only two objects are

Why is a Regexp object considered to be “falsy” in Ruby?

孤街醉人 提交于 2019-12-03 05:28:57
Ruby has a universal idea of " truthiness " and " falsiness ". Ruby does have two specific classes for Boolean objects, TrueClass and FalseClass , with singleton instances denoted by the special variables true and false , respectively. However, truthiness and falsiness are not limited to instances of those two classes, the concept is universal and applies to every single object in Ruby. Every object is either truthy or falsy . The rules are very simple. In particular, only two objects are falsy : nil , the singleton instance of NilClass and false , the singleton instance of FalseClass Every

Does Ruby's Enumerable#zip create arrays internally?

自作多情 提交于 2019-11-27 19:24:02
问题 In Ruby - Compare two Enumerators elegantly, it was said The problem with zip is that it creates arrays internally, no matter what Enumerable you pass. There's another problem with length of input params I had a look at the implementation of Enumerable#zip in YARV, and saw static VALUE enum_zip(int argc, VALUE *argv, VALUE obj) { int i; ID conv; NODE *memo; VALUE result = Qnil; VALUE args = rb_ary_new4(argc, argv); int allary = TRUE; argv = RARRAY_PTR(args); for (i=0; i<argc; i++) { VALUE ary

How can I redefine Fixnum's + (plus) method in Ruby and keep original + functionality?

血红的双手。 提交于 2019-11-27 16:38:18
问题 This throws me a SystemStackError in 1.9.2 Ruby ( but works in Rubinius ): class Fixnum def +(other) self + other * 2 end end but there is no super for + (based on other errors). How can I access the original + functionality? 回答1: Use alias_method . Alias Fixnum 's + to something else, then refer to it in the new + : class Fixnum alias_method :old_add, :+ def +(other) self.old_add(other) * 2 end end 回答2: Another interesting approach would be to pass a block to Fixnum's module_eval method. So,