I was looking at this line:
extensions << Module.new(&block) if block_given?
It seems to create a new module and add it to an arry.
Why would you build a module from a block though? The block could be anything and then the extensions array becomes unpredictable.
Edit: This is from Sinatra's base class:
def register(*extension...
How can I do what they are talking about here, but in Ruby?
How would you do the function on an object? and how would you do a global function (see jetxee's answer on the post mentioned)?
EXAMPLE CODE:
event_name = "load"
def load()
puts "load() function was executed."
end
def row_changed()
puts "row_changed() function was execu...
if i have a.rb:
require 'rack'
require 'b'
and my b.rb is:
//do something with rack
Does b.rb need to also say:
require 'rack'
if b.rb will only ever be 'require'd by a.rb?
I'm seeing a lot of code where a.rb requires 'rack' and includes b.rb which also requires 'rack'.
...
This is my first time working with Markov chains.
I want to combine two sources of text and get a readable Markov Chain. The implementation I'm using is here - the sources of text are stripped of markup, etc.
I was first exposed to Markov Chains with the Ruby Rbot IRC bot. Their Markov plugin source is here.
I'm finding my use of the...
Smarty Pants sounds like a cool idea to me:
SmartyPants can perform the following transformations:
Straight quotes ( " and ' ) into “curly” quote HTML entities
Backticks-style quotes (``like this'') into “curly” quote HTML entities
Dashes (“--” and “---”) into en- and em-dash entities
Three consecutive dots (“...”) into an ellipsis en...
If I have a whole bunch of requires in my main app file:
require 'a'
require 'b'
require 'c'
require 'd'
require 'e'
require 'f'
require 'g'
require 'h'
require 'i'
require 'j'
would it be bad practice to put strip all of these requires out and put them in a separate file that just does all of the requires - let's call it 'all_require...
I am using the standard jekyll installation to maintain a blog, everything is going fine. Except I would really to tag my posts.
I can tag a post by using the YAML front matter, but how do I generate pages for each tag that can will list all posts for a tag?
...
The problem: we have jobs that run from a few seconds to a few minutes in BackgroundRB from a Rails app. But, what happens when we deploy new code and restart BackgroundRB when it's performing a task? BackgroundRB does not seem to pick up any 'taken' tasks and I have not been able to find anything that can recover these tasks.
Can anyo...
What are the behavioural differences between the following two implementations in Ruby of the thrice method?
module WithYield
def self.thrice
3.times { yield } # yield to the implicit block argument
end
end
module WithProcCall
def self.thrice(&block) # & converts implicit block to an explicit, named Proc
3.times { b...
I have written a simple ruby gem to scrape a set of websites, providing a simple API, inside the gem itself I have included a retry method... to attempt to use Hpricot 3 or more times on failure mostly due to timeouts.
def retryable(options = {}, &block)
opts = { :tries => 1, :on => Exception }.merge(options)
retry_exception, retri...
On my mac 10.5 when I use the command OpenSSL::Digest::Digest.new('sha256') I get Unsupported digest algorithm (sha256). Does anyone know how to solve this?
...
I'm using ruby-libnotify in a Ruby GTK app, and it works great to create a bubble popup in Ubuntu. I'm on Hardy, and it all works great. Then I had others try the app on Jaunty, and instead of a bubble popup with the new Notify-OSD system, as I expected, the notification turned into a dialog box.
I looked into it, and found the Ubuntu...
I would like to add a couple of instance variables to my controller, since the variables in question are required from within more than one action's view. However, the below example does not work as I would expect.
class ExampleController < ApplicationController
@var1 = "Cheese"
@var2 = "Tomato"
def show_pizza_topping
# What ...
I have a rake task that uploads a list of files via ftp. Copying without threading works fine, but it would be faster if I could do multiple concurrent uploads.
(I'm new to ruby and multithreading, so no surprise it didn't work right off the bat.)
I have:
files.each_slice(files.length / max_threads) do |file_set|
threads << Thread....
I have my index page which posts a single entry instead of the usual scaffold default of all of the entries. I told it to link to an action and it just responds to "Couldn't find Post with ID=all". It is the same as the default index method and index view. I assume this has something to do with routing but being no I have no clue. Any id...
I want to create a list from a class' attributes
I'm new with ruby- i have an activerecord class called fixture and what an array of "Home Team", "Draw", "Away team", where home team and away team are both fields in the Fixture table
I have come up with the following code sticking it in the Fixture class- how do access the values of th...
I understand how to check for a pattern in string with regexp in ruby. What I am confused about is how to save the pattern found in string as a separate string.
I thought I could say something like:
if string =~ /regexp/
pattern = string.grep(/regexp/)
and then I could be on with my life. However, this isn't working as expected an...
How can class variables of a module be updated or accessed by methods availabe to that module by include/extend mechanisms?
Say module A has a class variable called @@foo; also that module includes/extends another B, which has some methods that would like to update class variables of the module, can they ?
For example, i want to write ...
Hi there,
What's Ruby for the following?
if executing the next line wouldn't cause any kind of error then
execute this line
elsif executing the next line wouldn't cause any kind of error then
execute this line
else
I've been reading the API pages for rescue and exceptions and eval but so far have failed in my quest.
Many thanks,...
Hi to all
I want to know how a ruby Script is call from a Xcode Application.Is this possible?
if yes plz guide me.
Thanks
...