ruby-1.9.3

How the @,x,X directives work with Ruby pack()/unpack() method?

穿精又带淫゛_ 提交于 2019-12-06 00:12:16
I just went through the Ruby Doc . But there is no sufficient code to understand how the below three are used in Real life programming: @ , X , x . can anyone explain it with a simple snippet? Thanks I will give you few example and will be learning together with you: [1,2,3,4].pack("CCCC") => "\x01\x02\x03\x04" So serializes in unsigned chars. Every letter in new byte. [1,2,3,4].pack("CCXCC") => "\x01\x03\x04" [1,2,3,4].pack("CCXXC") => "\x03" Think of the 'X' as backspace directive [1,2,3,4].pack("CCxC") => "\x01\x02\x00\x03" [1,2,3,4].pack("CCxxC") => "\x01\x02\x00\x00\x03" 'x' places zero

implement a rails before_filter in ruby without rails

六眼飞鱼酱① 提交于 2019-12-05 21:18:13
问题 I am using g a logger in all of my classes. I want each msg to begin with class name and method name like so: Class_name::Method_name this is what i'm doing now : class FOO def initialize end def bar msg_prefix = "#{self.class}::#{__method__}" ... some code ... @logeer = "#{msg_prefix} msg ..." end def bar2 msg_prefix = "#{self.class}::#{__method__}" ... some code 2 ... @logeer = "#{msg_prefix} msg2 ..." end end i want to use a before_filter like in rails to prevent duplicity, I am using

Installing ruby-debug-base19 on Windows in Ruby 1.9.3

佐手、 提交于 2019-12-05 04:44:09
I need to install ruby-debug-base19 in order to active debug on Netbeans IDE, when I execute: $ gem install ruby-debug-base19 I got the following error. Extracted from log generate C:/Ruby193/bin/ruby.exe extconf.rb checking for rb_method_entry_t.body in method.h... no checking for vm_core.h... no C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/ruby_core_source.rb:39: Use RbConfig instead of obsolete and deprecated Config. checking for rb_method_entry_t.body in method.h... no checking for vm_core.h... yes checking for iseq.h... yes checking for insns.inc... yes checking for

Where does `singleton` methods reside in Ruby?

有些话、适合烂在心里 提交于 2019-12-04 16:56:29
I was playing with singleton class in my IRB. And doing so tried the below snippets. class Foo ; end #=> nil foo = Foo.new #=> #<Foo:0x2022738> foo.define_singleton_method(:bar , method(:puts)) #=> #<Method: Object(Kernel)#puts> Here above I just created a singleton method on instance of class Foo . foo.bar("hi") hi #=> nil foo.singleton_methods #=> [:bar] foo_sing = foo.singleton_class #=> #<Class:#<Foo:0x2022738 foo_sing.is_a? Class #=> true foo_sing.instance_of? Class #=> true foo_sing.inspect #=> "#<Class:#<Foo:0x1e06dc8>>" In the above I tried to create a singleton class on instance of

How can I find a memory leak on Heroku?

筅森魡賤 提交于 2019-12-04 09:04:30
问题 I have a Rails 3.2.8 app running on Heroku Cedar with Ruby 1.9.3. The app runs fine when it launches but after a day or so of continuous use, I start to see R14 errors on my logs. Once the memory errors start, they never go away, even if the app is idle for several hours. Shouldnt the garbage collector clean up unused objects after a while and reduce the memory load? It seems this is not happening on Heroku. Generally, memory usage starts to creep up after running some reports with several

Error while installing Ruby 1.9.3

三世轮回 提交于 2019-12-03 14:40:39
问题 I have an error while installing Ruby 1.9.3 through rvm. rvm install 1.9.3-p0 Installing Ruby from source to: /home/alder/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)... ruby-1.9.3-p0 - #fetching ruby-1.9.3-p0 - #downloading ruby-1.9.3-p0, this may take a while depending on your connection... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0^[[B^[[B^[[B^[[B^[[B^[[B^[100

Thinking sphinx doesn't start - “Failed to start searchd daemon”

拟墨画扇 提交于 2019-12-03 14:08:49
I try to start thinking sphinx on my server but it doesn't want to work. I do: $ rake thinking_sphinx:index && rake thinking_sphinx:start And i get: Generating Configuration to /vol/www/apps/ror_tutorial/releases/20120202111730/config/development.sphinx.conf Sphinx 2.0.3-release (r3043) Copyright (c) 2001-2011, Andrew Aksyonoff Copyright (c) 2008-2011, Sphinx Technologies Inc (http://sphinxsearch.com) using config file '/vol/www/apps/ror_tutorial/releases/20120202111730/config/development.sphinx.conf'... indexing index 'micropost_core'... WARNING: collect_hits: mem_limit=0 kb too low,

Is it possible to run my Rails app on Heroku with Ruby 1.9.3? If so, how?

故事扮演 提交于 2019-12-03 07:26:26
问题 I tried this tip: https://github.com/thoughtbot/laptop/pull/14#issuecomment-3192270 . On deploy I see -----> Using RUBY_VERSION: ruby-1.9.3-p0 But my logs show the environment variable is not respected INFO ruby 1.9.2 (2011-07-09) [x86_64-linux] Hacky / experimental solutions accepted! Edit: I am on the cedar stack. 回答1: Here's an update for everyone referencing this question... Heroku now allows you to specify your ruby version in your Gemfile, thanks to their addition to the latest version

ActiveRecord objects in hashes aren't garbage collected — a bug or a sort of caching feature?

一曲冷凌霜 提交于 2019-12-03 02:44:41
问题 I have a simple ActiveRecord model called Student with 100 records in the table. I do the following in a rails console session: ObjectSpace.each_object(ActiveRecord::Base).count # => 0 x = Student.all ObjectSpace.each_object(ActiveRecord::Base).count # => 100 x = nil GC.start ObjectSpace.each_object(ActiveRecord::Base).count # => 0 # Good! Now I do the following: ObjectSpace.each_object(ActiveRecord::Base).count # => 0 x = Student.all.group_by(&:last_name) ObjectSpace.each_object(ActiveRecord

How can I find a memory leak on Heroku?

青春壹個敷衍的年華 提交于 2019-12-03 01:53:05
I have a Rails 3.2.8 app running on Heroku Cedar with Ruby 1.9.3. The app runs fine when it launches but after a day or so of continuous use, I start to see R14 errors on my logs. Once the memory errors start, they never go away, even if the app is idle for several hours. Shouldnt the garbage collector clean up unused objects after a while and reduce the memory load? It seems this is not happening on Heroku. Generally, memory usage starts to creep up after running some reports with several thousand rows of data, although results are paginated. How can I find the memory leak? Plugins like bleak