ruby

Ruby on Rails - access user defined lib functions in /lib/login_system.rb from app/views/layouts/_menu.rhtml

I have defined a function called is_logged_in? in a user defined library stored in the /lib directory, however when I try to use it in one of my views (in this case a _menu.html.erb view) I get a "undefined method `is_logged_in?' for #" error. I had assumed that if the method was available within the /lib directory then it would be acces...

convert php to ruby

I changed the Ruby snippet and now it works, I had forgotten to add the md5 part int he previous post, sorry. Afterwards I retested the PHP snippet as well, and both outputs are the same now. Here is what I have so far: PHP: "Inx ".base64_encode('Jon').' '.base64_encode(pack( 'H*' , md5($message."werty"))) Ruby: md5 = Digest::MD5.d...

difference between Nokogiri::XML(File.open()) and Nokogiri.parse(open())

I tried opening xml file using both the ways, but only the latter part worked when I tried to use xpath. eg., doc = as in title; doc.xpath('//feed/xyz'), worked only when I open the file using parse method. One thing I noted was, the object when I open using XML:: is Nokogiri::XML::Document, while the latter one was Nokogiri::HTML...

convert RSA public key to RSA DER

Hello., I have id_rsa.pub key generated by ssh-keygen. I need to prigrammically convert id_rsa.pub to RSA DER formatted key. How it is possible? Preferably ruby language but I would be glad for algorythm in any language. ...

how to store the name of nested files in a variable and loop through them in rake

I have the following rake file to create a static version of my sinatra app, stolen from http://github.com/semanticart/stuff-site/blob/master/Rakefile class View attr_reader :permalink def initialize(path) filename = File.basename(path) @permalink = filename[0..-6] end end view_paths = Dir.glob(File.join(File.dirname(__...

DataMapper Many-To-Many Association using Sinatra

I just stared learning Sinatra and DataMapper while building a simple blog. I seem to have encountered a problem getting my Many-To-Many association working. I'm trying to associate categories with posts. Upon creation of a post, the category association is not created. Here are my models: class Post include DataMapper::Resource ...

Accessing id in a just built object

Hi, I have a rails app where I have clusters and users in a belongs_to has_many relationship. In the cluster_controller create method I write: @cluster = @current_user.clusters.build(params[:cluster]) now I want to run some commandline script: output = `echo cluster#{@cluster.id} > /tmp/out` ...rest of function here I also tried...

Getting executed command from ruby FileUtils

When you pass the :verbose flag to a FileUtils command, the command gets printed to stdout - is there a way to capture the command so it can be logged or used elsewhere? ...

Get a class by name in Ruby?

Having a string with the module and name of a class, like: "Admin::MetaDatasController" how do I get the actual class? The following code works if there's no module: Kernel.const_get("MetaDatasController") but it breaks with the module: ruby-1.8.7-p174 > Kernel.const_get("Admin::MetaDatasController") NameError: wrong constant nam...

Ruby Subclasses: Including Different Modules Based on Inheritance

I have two classes, Task and Subtask. Subtask varies very little from Task except for one important thing, it must include a different module. The included modules, subtask_module and task_module, both have the same methods and aliases for my purposes, but internally they function a little differently once the included module extends it...

Regex in rails to match [\w] and "-" but not numbers

Hello , I want to write a regular expression for First name validation . The regular expression should include all alphabets (latin/french/german characters etc.). However I want to exclude numbers from it and also allow -. So basically it is \w (minus) numbers (plus) -. Please help. ...

Why is Ruby's Array.map() also called Array.collect()?

Whenever I see Ruby code that says: arrayNames.collect { ... } I forget what collect is and have to look up what it is, and find that it is the same as map(). Map, I can understand, mapping 1 byte to a pixel, and function is to map an x to a y, a 2 to a 4, a 5 to a 25, etc. But where does the name "collect" come from? Maybe that wi...

Is it possible to test Java application with Capybara?

Hi I like the overall idea of Capybara, but i can't run it against the Java application for some reason. Is that possible at all? Thank you ...

Free tool for automating GUI testing of a Windows Forms application and a Web application

Is there a way to automate GUI testing of a Windows Forms application and a web application (HTML) using free tools? For example, Ruby + Rspec + Watir work great for web UI testing. IronRuby + Rspec can work for winforms apps. Does anybody know a tool that can do both, WinForms and Web? ...

Manipulating biiig XML documents

Hi, I want to parse a XML file, change some attributes and write the results in a new XML file. The given XML file is very huge (approx. 2 GB). Does anyone have experiences handling such XML files using Ruby and can recommend me a library? Best regards ...

Multiple initialization of auto-vivifying hashes using a new operator in Ruby

I would like to initialize several auto-vivifying hashes by one-line expression. So far I came to an extra method for the AutoHash object: class AutoHash < Hash ... def few(n=0) Array.new(n) { AutoHash.new } end which allows me to do the following a, b, c = AutoHash.new.few 3 However, I feel that one can make the followin...

Confusing behaviour of const_get in Ruby?

According to the documentation mod.const_get(sym) "Returns the value of the named constant in mod." I also know that const_get by default may look up the inheritance chain of the receiver. So the following works: class A; HELLO = :hello; end class B < A; end B.const_get(:HELLO) #=> :hello I also know that classes in Ruby subclass Obj...

Beginner Ruby question - what does the ${...} notation in String literals do?

I'm reading some Ruby code and I don't understand this snippet: thing = '${other-thing}/etc/' It appears to substitute a value for the ${other-thing} and use that to build the String thing but I haven't been able to recreate this myself. EDIT: Sorry to all, it turns out there was some preprocessing going on by Maven (a Java build too...

Ruby string strip defined characters

in Python, we can e.g. "[foo ]".strip(" []") # -> "foo" how do we do this in Ruby? string strip method is stripping only whitespace .. UPDATE stripping is not deleting! : ) "[ foo boo ]".strip(" []") # -> "foo boo" ...

How can I get the path for the last created file in a directory using Ruby?

How can I get the path for the last created file in a directory using Ruby? ...