I'm trying to add conditional logic to determine if there's one regex match for a URL in a string. Here's an example of the string:
string_to_match = "http://www.twitpic.com/23456 ran to catch the bus, http://www.twitpic.com/3456 dodged a bullet at work."
I only want to match if I determine there's one URL in the string, so the above...
Here's some test code that explains the issue I'm having. The Child class calls methods on the Parent class. One of the Parent's methods defines a new method called foo on the Parent. After foo is defined, attempting to call it from Child class works, but the context is completely different (I can only access Child's instance variables, ...
I wrote a web application in ROR, but I want it supports web service, so that I can do the same things on non-web application platform. What should I do to add web service ability to my web application... ...or I need to reinvent my application, to write a separate web service independently?
...
Most things that look like operators are methods in Ruby; 1 + 2 is syntactic sugar for 1.+(2).
Even though + and * are methods that a program can redefine, Ruby has special magic to evaluate 1 + 2 * 3 as 1.+(2.*(3)) instead of 1.+(2).*(3).
I wonder where this special magic lives in Ruby--if it is hard-wired into the interpreter.
Ari.
...
What is a good method in Ruby to prevent SQL Injection?
...
It seems to be very counter productive in that so many gems will break on windows. I have been dealing with so many mysql and ruby-mysql gem problems (seg faults occuring in the gem itself, a class called UnixSocket apparently doesn't work well on windows machines, etc etc).
I'm I just wasting my time here? Should I move onto a differen...
I have a string "1/16" I want to convert it to float and multiply it by 45. However, I dont get the desired results.
I am trying in script/console
>> "1/16".to_f
=> 1.0
>> "1/16".to_f*45
=> 45.0
how can i get the desired result of 2.81
Bigger picture:
I have a drop down like this:
<%=select_tag :volume, options_for_select(["",...
Hey,
In a little Sinatra app I'm working on, I want to store what I write in a textarea into a text file. What's the simplest way to do this?
...
Possible Duplicates:
Ruby/Ruby on Rails ampersand colon shortcut
What does map(&:name) mean in Ruby?
I was reading Stackoverflow and stumbled upon the following code
array.map(&:to_i)
Ok, it's easy to see what this code does but I'd like to know more about &: construct which I have never seen before.
Unfortunately all I ...
So I'm fairly new to ruby in general, and I'm writing some rspec test cases for an object I am creating. Lots of the test cases are fairly basic and I just want to ensure that values are being populated and returned properly. I'm wondering if there is a way for me to do this with a looping construct. Instead of having to have an asser...
I don't understand why some people use the percentage syntax a lot in ruby.
For instance, I'm reading through the ruby plugin guide and it uses code such as:
%w{ models controllers }.each do |dir|
path = File.join(File.dirname(__FILE__), 'app', dir)
$LOAD_PATH << path
ActiveSupport::Dependencies.load_paths << path
ActiveSupport...
I'm trying to take a string which is a simple math expression, remove all spaces, remove all duplicate operators, convert to single digit numbers, and then evaluate.
For example, an string like "2 7+*3*95" should be converted to "2+3*9" and then evaluated as 29.
Here's what I have so far:
expression.slice!(/ /) # Remove whitespace
exp...
I am scraping forum website by type (article, webinar, video) I thought if ruby can extract somehow the length of the video. The corresponding html part of the web page looks like.
<div align="center"><script type="text/javascript" src="http://somedomain.com/wp-content/themes/thesis/custom/swfobject.js"></script>
<div id="play...
in my ruby script I need to pass user name and
password as a plain text in a form in order to log in. Both user name and password are currently stored in my script.
I have no control over the server I log in from the script. The script is localy working fine and in the future I want to move to onto my
webhosting provider and run it ...
I have a singular nested resource like so:
map.resources :bookings, :member => { :rate => :post } do |booking|
booking.resource :review
end
Giving me these routes:
new_booking_review GET /bookings/:booking_id/review/new(.:format) {:controller=>"reviews", :action=>"new"}
edit_booking_review GET /bookings/:booki...
Hi,
I've built my first gem but I don't seem to be able to get it to install correctly. I can issue the command
sudo gem install ceilingfish-toto
Which produces the output
Successfully installed ceilingfish-toto-0.3.6
1 gem installed
But when I then type gem which ceilingfish-toto. I get the output
Can't find ruby library file or ...
[Later: Still can't figure out if Groovy has static typing (seems that it does not) or if the bytecode generated using explicit typing is different (seems that it is). Anyway, on to the question]
One of the main differences between Groovy and other dynamic languages -- or at least Ruby -- is that you can statically explicitly type varia...
I'm running into a rather odd problem with Ruby and File.chmod (same problem exists with FileUtils.chmod.
Here is what I am doing for a test case:
File.chmod(1777, "testfile")
But once I have done that, I get this as a permission set:
--wxrwS--t
This problem only exists when using the *nix 4 digit permission sets. I googled it, b...
Hello, I am creating a project, and I need to be able to use a regex(or if something else is preferable?)
Basically, I need to convert a PHPish markup code page so that the "non-code" is converted into "code." For instance:
Orginal:
<?code
echo 'some text';
?>
<head>
</head>
<body>
</body>
<?code
echo '</html>';
?>
Converted:
...
class HelloApp
attr_accessor :label, :text_field, :button
def clickedButton(sender)
# implementation
your_name = self.text_field.stringValue
self.label.stringValue = "Hello, #{your_name}"
end
end
The above code is in HelloApp.rb
The problem is when I type something into the t...