I want to add a folder ~/Projects/Scripts so I can use require script where script is a ruby file in this directory.
How does the require ruby method works? Does it load from a enviornment variable and if so what?
...
I'm currently working through some code katas in multiple languages (Ruby, Perl, Python)/frameworks (Rails, Django, Mojo). It seems every time I start a new project from scratch I end up tweaking files to my liking, even after using things like newgem, module-starter, script/generate, startapp, etc.
For those who program in many differe...
Hi,
how do I pass a 2-dimensional array from javascript to ruby, please? I have this on client side:
function send_data() {
var testdata = {
"1": {
"name": "client_1",
"note": "bigboy"
},
"2": {
"name": "client_2",
"note": "smallboy"
}
}
consol...
I have a method song_link that calls link_to internally. I want the caller to be able to pass an options hash to song_link, which will then use the options relevant to it, and pass the rest to link_to. Here's my code:
def song_link(song, separator = nil, options = {})
if separator.class == Hash
options = separator
sepa...
When i use User.count(:all, :group => "name"), i got multi rows, but it's not i want, what i want is the count of the rows, how can I do it?
...
Hi,
I have a problem with RubyCocoa, which has a weak link to a libruby.dylib and not always can find this dylib on user's computer, which resulting a crash on the launch of my application (RubyCocoa based). I wonder whether it's possible to copy Ruby.framework to the bundle of my application and tell somehow to RubyCocoa to look for ru...
Helo,
I am pretty new to Ruby (using 1.8.6) and need to know whether the following functionality is available automatically and if not, which would be the best method to implement it.
I have class Car.
And have two objects:
car_a and car_b
Is there any way I could do a compare and find what properties differ in one of the objects a...
I've been playing around with HPricot, but after a fair amount of searching, I've not been able to work this out.
I'm trying to parse a HTML page and find all tags with a href to an mp3 file. So far I've got
<ul>
<% @page.search('//a[@href*=mp3]').each do |link| %>
<li>
<%= link.inner_text %>
</li...
this is the problem:
inside a lib i need to print MONTHNAMES to string
if i try
Date::MONTHNAMES.inspect
result is
=> "[nil, \"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"]"
that's good but i don't need the first element, so
month_n...
I just saw that whitehouse.gov is using drupal as a CMS and portal technology.
One of the advantages of drupal seems that it is easy to add plugins and that programming is minimum, i.e. that re-inventing the wheel is at minimum. That is actually exactly the DRY philosophy of Ruby-on-Rails. So:
What are the drawbacks of drupal?
What wou...
Scenario:
I have to call an external program from my Ruby script, and this program sends a lot of useful (but cryptic) info to stdout and stderr.
While the program is running, I'd like to parse the lines it sends to stdout and stderr and:
Remove them if not necessary
Reformat/replace them if necessary
I tried all the usual tricks (...
The following returns whatever integer I feed it as a parameter.
def space(spacer_count)
spacer_count.times do
image_tag("24gray/spacer.png", :class => "spacer")
end
end
How do I make it return the desired number of images? E.g., I want space(6) to return six copies of spacer.png, not the number "6".
Thanks!
...
How can I do this on Ruby?
puts some_method("ò")
# => "ò"
In other words convert an accented character like ò to his HTML version: ò
I tried like this:
# coding: utf-8
require 'rubygems'
require 'htmlentities'
require 'unicode'
coder = HTMLEntities.new
string = "Scròfina"
puts coder.encode(string, :named)
but what I...
Hi guys, I need to pass self as object not class to :conditions string, is there any way to do this?
has_many :topic,
:class => 'FileTopic',
:conditions => "id in (select * from file_topics where program_id = #{self.id})"
My problem is self is always giving me the id of the class but not the instance of the class. I guess has_many is ...
I am writing a Ruby app at the moment which is going to search twitter for various things. One of the problems I am going to face is shared results between searches in close proximity to each other time-wise. The results are returned in an array of objects each of which is a single tweet. I know of the Array.uniq method in ruby which ret...
I'm having problems uploading a file through the OAuth gem (0.3.6).
The way I call it is:
response = @access_token.put( args[ 0 ], args[ 1 ],
{ 'Accept' => 'application/xml', 'Content-Type' => 'multipart/form-data' } )
args is an array, [ 0 ] is the url I want to send the multipart form, [ 1 ] is the hash of parameters.
I'm using...
I ran "gem sources -c" so that I have to deliberately specify where I want to install a gem from since I now have 3 different sources for gem installs - RubyForge, Github and Gemcutter.
C:\>gem sources -c
*** Removed specs cache ***
*** Removed user source cache ***
*** Removed latest user source cache ***
*** Removed system source cach...
Is there anything in Ruby that will return me an array of characters belonging to a certain Unicode category? In particular, I'd like to have the Mn category so that I can follow the advice on this answer.
...
I could use some help on including and extending Ruby modules and classes.
My previous question handled the named routes, but not all of the view/tag helpers due to the default_url_options Hash. The issue here is that ActionController::UrlWriter methods, like url_for, call the class attribute default_url_options. So when including Act...
I'm working on a RoR app, but this is a general question of strategy for OOP. Consider the case where there are multiple types of references that you are storing data for: Books, Articles, Presentations, Book Chapters, etc. Each type of reference is part of a hierarchy where common behaviors sit at the most general point of inheritance, ...