ruby

How to get error messages from ruby threads

I'm having a problem right now where I can't see where my child threads are spitting out error messages which is making it difficult to debug. eg: Thread.new{ a = 1/0 } Is there any way to have all thread errors print out at stderr? ...

Preferred ruby plugin for Eclipse?

RDT seems to be the preferred ruby plugin for adding ruby language support to Eclipse. However, I see that the main developer on that project has joined Aptana RadRails. Does this mean that project is no longer up-to-date for Ruby in Eclipse. If so, which plugin is the preferred choice these days? ...

What's the correct way to log a user out of a Rails application?

I'd like to provide a "log out" function in a Rails app. Should I do... session.delete or reset_session From reading the docs, both look like they could work. Does it matter? Or should I use something else? ...

Replace 2 strings at the same time?

hello how can I replace 2 strings in the same time? for example let's say I have string like this: str1 = "AAAA BBBB CCCC DDDD" i want to replace every "AAAA" with "CCCC" and every "CCCC" with "AAAA" but if i did: str1.gsub("AAAA","CCCC") # CCCC BBBB CCCC DDDD str1.gsub("CCCC","AAAA") # AAAA BBBB AAAA DDDD what I want str1 to be "C...

Search Web Page Content

How do you search the Web Page Source in ruby Hard to explain, but heres a the code for doing it in Python import urllib2, re word = "How to ask" source = urllib2.urlopen("http://stackoverflow.com").read() if re.search(word,source): print "Found it "+word ...

Ruby Regex Help

I want to Extract the Members Home sites links from a site. Looks like this <a href="http://www.ptop.se" target="_blank"> i tested with it this site http://www.rubular.com/ <a href="(.*?)" target="_blank"> Shall output http://www.ptop.se, Here comes the code require 'open-uri' url = "http://itproffs.se/forumv2/showprof...

how to configure tomcat to handle rhtml pages using jruby?

How can I configure tomcat to handle .rhtml pages with jruby? I guess I should mess around with the web.xml file, but I don't know how... (ideally, without rails, just the necessary stuff to use erb for rendering rhtml pages...) ...

What does !! mean in ruby?

Just wondering what '!!' is in ruby. thanks! ...

Ruby Regex Help

Hi im learning Ruby Regex, but having once problem here. I want to extract links from google.com Code i shall extract from looks like this <a href="http://www.test.com/" class="l" I took me around 5min to found a regex that shall works. (with www.rubular.com) It is "(.*?)" class="l" Heres Comes the code require "open-uri" u...

Ruby Unit::Test comparing html output by ignoring whitespace

Hi All, I am using Ruby's Test::unit to compare the result of generated html with the expected result. (not using rails). I am not concerned with whitespace differences but these nearly always crop up during tests. Is there any testing mechanism to compare html while ignoring meaningless whitespace. I can see there's similar question f...

How to embed a gem into a RubyCocoa app?

I'd like to embed 2 gems into my RubyCocoa app, so the user doesn't have to install them on the console on him-/herself. But I can't find any information on about how to do that. ...

Advanced ruby question: binding of procs

Hi All, Is it possible to execute a proc within the context of another object? I know that normally you'd do proc.call(foo), and then the block should define a parameter. I was wondering though whether I could get "self" to bind to foo so that it's not necessary to have a block parameter. proc = Proc.new { self.hello } class Foo de...

How compatible are rspec and heckle?

I'm currently using test/unit, and I'm considering using rspec. However, I've noticed that rspec currently doesn't support heckle in ruby 1.9.1, and doesn't support passing any parameters to heckle apart from the target module/class/method. Are there any other current problems with using heckle and rspec, or do they work well together a...

Pathname.rb error on running a minitest testcase

I'm running ruby 1.8.6. I installed the minitest 1.3.1 gem, which is the new defacto replacement for the Test::Unit framework in Ruby 1.9 The API is supposed to be the same. I wrote a small test to get things rolling require 'rubygems' gem 'minitest' require 'minitest/unit' MiniTest::Unit.autorun class CategoryMiniTest < MiniTest::U...

What Next: C++, Python or Ruby

So I am a long time .Net developer looking to branch into something new to further my professional development. I have reduced the next language to learn as one of c++, Python or Ruby and want to hear everyone's thoughts on what I should pick, and why? What trials and tribulations have others found when moving from c# onto one of these...

How to search for language syntax in Google?

My current question is what does the << operator do in Ruby? But my real question is how would I search Google to find the answer? ...

Tuples in Ruby

Does anyone use tuples in Ruby? If so, how may one implement a tuple? Ruby hashes are nice and work almost as well, but I'd really like to see something like the Tuple class in Python, where you can use . notation to find the value for which you are looking. I'm wanting this so that I can create an implementation of D, similar to Dee for...

Add shortcut methods or follow ActiveRecord semantics?

Yet another argument with a friend of mine. Consider this code: class User < ActiveRecord::Base has_many :groups def in_group?(group) groups.include?(group) end end class Group < ActiveRecord::Base has_many :members def add_user(user) members << user end end My opinion is that these methods add extra unnecessar...

JRuby/Windows and (native) extensions how do I distinguish them?

I've tried to use EventMachine etc., with JRuby. I get errors about native extensions. I believe this is due to Java limitations. I think the fact that I am on Windows further complicates the issue. Some clarification would be appreciated. What extensions can/can't be used with JRuby? How can I tell? Thanks. ...

What is the best way to write a rakefile to run commands in windows?

As an example i want to run the following command under a rake. robocopy C:\Media \\other\Media /mir The rakefile i was able to get working was def sh(str) str.tr!('|', '\\') IO.popen(str) do |pipe| pipe.each do |line| puts line end end end task :default do sh 'robocopy C:|Media ||other|Media /mir' end Howeve...