Using Ruby, how can I take a string and insert pipes between the words?
Let's say I have this string: "birthday cake is my favorite" I need to convert that to: "birthday|cake|is|my|favorite" How would I go about doing that with Ruby? ...
Let's say I have this string: "birthday cake is my favorite" I need to convert that to: "birthday|cake|is|my|favorite" How would I go about doing that with Ruby? ...
Why is is that the following fails? module Test def test puts "test" end puts "testing" test end I get this output: testing test.rb:6:in `test': wrong number of arguments (ArgumentError) from test.rb:6:in `<module:Test>' from test.rb:1:in `<main>' Is it because the module hasn't been "compiled" yet,...
I am purely a windows programmer and spend all my time hacking VC++. Recently I have been heading several web based applications and myself built applications with python (/pylons framework) and doing projects on rails. All the web projects are hosted on ubuntu linux. The RELEASE procedures and check list we followed for building and...
I've searched and I've found a lot that are antiquated. Any suggestions? ...
Hi My friend has a forum, which is full of posts containing information. Sometimes she wants to review the posts in her forum, and come to conclusions. At the moment she reviews posts by clicking through her forum, and generates a not necessarily accurate picture of the data (in her brain) from which she makes conclusions. My thought to...
Hi, as a warning I am completly new to Ruby (been learning for 1 day) so please explain in simple terms. how do I make \n actually work in my output? At the moment it just writes it all in 1 long block. Thanks for any help Dir.chdir 'C:/Users/name/Music' music = Dir['C:/Users/name/Music/*.{mp3, MP3}'] puts 'what would you like to call ...
I understand that in JSON, keys are supposed to be surrounded in double quotes. However, I'm using a data source which doesn't quote them, which is causing the Ruby JSON parser to raise an error. Is there any way to perform 'non-strict' parsing? Example: >> JSON.parse('{name:"hello", age:"23"}') JSON::ParserError: 618: unexpected token...
I am wondering if this is true: When I take the square root of a squared integer, like in f = Math.sqrt(123*123) I will get a floating point number very close to 123. Due to floating point representation precision, this could be something like 122.99999999999999999999 or 123.000000000000000000001. Since floor(122.999999999999999999) ...
I've run into a problem with my very simple Ramaze project. My project is identical to the prototype project that is generated from 'ramaze create mywebsite', except that I'm using Haml templates (I set 'engine :Haml' in controller/init.rb). Here are the steps to reproduce the problem: Start the development server. I'm using Thin. V...
I'm writing a library that depend on a specific gem. I require the gem and use it in my code and everything is hunky-dory as long as the gem is installed on the user's machine. but what if it is not?! I thought it's fine cause I can rescue from the require command and print a message to the output to inform the user about the lacking ge...
I'd like to write notes for class in plain text. I was wondering if there was a markup language for doing this, where I could parse the notes for key terms, titles, page #s etc programmatically with a language such as Ruby or Python. ...
This is more a question of semantics than anything else. I'd like to check if a variable is either one of two values. The easiest way of doing this would be: if var == "foo" || var == "bar" # or if var == 3 || var == 5 But this doesn't feel very DRY to me. I know I can use String.match(), but that doesn't work for non-string vari...
Hi all I have just installed ruby+mechanize. It seems to me that it is posible in ruby nokogiri what I want to do but I do not know how to do it. What about this table? It is just part of html of vBulletin forum site. I tried to keep the html structure but deleted some text and tag attributes. I want to get some details per thread like...
Hi , I want to write a ruby program that could inspect the variable value of a program by launch the gdb and then print that value. How could I achieve this? If I were in the shell, I would do this : shell > gdb test [...gbd started] (gdb) p variable $1 = 20 (gdb) I also like to hear other ways that can achieve the same g...
I'm using restful_authentication plugin for Ruby on Rails. All seems fine except that it seems the user session is not getting created at all. I have the create method below. It appears that the self.current_user is being set but that the actual session is never created. When and how is the current_user_session supposed to be defined...
Hi, I have a remote embedded system and it is telnet-able. How can I fetch a binary file from it using ruby? If it were a text file, I could have used: con = Net::Telnet::new("Host"=>ip,"Timeout"=>200) #Host not host File.open("fetched_file","w+") do |f| con.cmd("cat /ect/file") {|data| f.write(data)} end But this wo...
Just for interest really - community wiki - how much Python can we get Ruby to understand ? [ Probably be just as interesting to do the reverse as well]. The experiment (such as it is) perhaps to see how much can be written in Ruby-Cross-Python scripts that will result in identical outputs. The only 'cheat' I guess being allowed here is...
I am trying to set up active records on top of a sqlite3 database with native ruby 1.8. This should work easily enough, I have seen plenty of examples out there that explain how. I am using some example code I have found, its pretty basic and starts with the following lines: require 'rubygems' require 'active_record' #require 'sqlite3-r...
I'm trying to build a desktop client that manages some downloads with Ruby. I would like to know how to go about trying to identify how much of the data is downloaded and the size of the entire data that is to be downloaded. Im trying to do this with Ruby so any help would be useful. Thanks in advance. ...
I would like to brake a long word in my Ruby on Rails string (something like <wbr> in HTML). Is it possible to tell Ruby "add character x in string y each z characters"? ...