In systems with apt-get:
# apt-get install libsqlite3-devIn systems with yum:
# yum install sqlite-devel
- The red metacoder side of a mad betacoder scientist -
# apt-get install libsqlite3-dev# yum install sqlite-devel
# apt-get install ruby1.8-dev
# yum install gcc
# yum install make
# yum install ruby-devel
# gem install bson_ext
require filename will:#!/usr/bin/ruby
class A
def original_method
puts "original content"
end
alias aliased_method original_method
alias_method :alias_methoded_method, :original_method
end
class B < A
def original_method
puts "modified content"
end
end
class C < A
def aliased_method
puts "modified content"
end
end
class D < A
def alias_methoded_method
puts "modified content"
end
end
[A, B, C, D].each do |klass|
puts "#{klass}:"
obj = klass.new
[:original_method, :aliased_method, :alias_methoded_method].each do |meth|
print "#{meth}: "
obj.send meth
end
puts
end
The results:
A: original_method: original content aliased_method: original content alias_methoded_method: original content B: original_method: modified content aliased_method: original content alias_methoded_method: original content C: original_method: original content aliased_method: modified content alias_methoded_method: original content D: original_method: original content aliased_method: original content alias_methoded_method: modified content
RewriteRule is running twice, even we use the [L] flag.RewriteCond), but the one I used is to put, as first rule, one to tell the RewriteEngine to do nothing if the URL is what I want:
RewriteEngine on
# index is the last rule - is what I want, so doesn't change anything
# and go to it (thank's to [L])!
RewriteRule ^index.php$ - [L,QSA]
# get user id - URL changed, so [L] will cause the new URL to be reparsed
# - and so it will be matched on the above rule.
RewriteRule ^user/(.*)$ index.php?user=$1 [L,QSA]
# in case of user/..., following rules don't apply,
# since the above rule has [L]
# ...
See this post in Portuguese.
ppp.rb (what is it?) which inspired me to implement my own version of a caller_binding method. Enjoy!#!/usr/bin/ruby
#
# (c) Sony Fermino dos Santos, 2011
# License: Public domain
# Implementation: 2011-07-30
#
# Published at:
# http://rubychallenger.blogspot.com/2011/07/caller-binding.html
#
# Inspired on:
# http://stackoverflow.com/questions/1356749/can-you-eval-code-in-the-context-of-a-caller-in-ruby/6109886#6109886
#
# How to use:
# return unless bnd = caller_binding
# After that line, bnd will contain the binding of caller
require 'continuation' if RUBY_VERSION >= '1.9.0'
def caller_binding
cc = nil # must be present to work within lambda
count = 0 # counter of returns
set_trace_func lambda { |event, file, lineno, id, binding, klass|
# First return gets to the caller of this method
# (which already know its own binding).
# Second return gets to the caller of the caller.
# That's we want!
if count == 2
set_trace_func nil
# Will return the binding to the callcc below.
cc.call binding
elsif event == "return"
count += 1
end
}
# First time it'll set the cc and return nil to the caller.
# So it's important to the caller to return again
# if it gets nil, then we get the second return.
# Second time it'll return the binding.
return callcc { |cont| cc = cont }
end
# Example of use:
def var_dump *vars
return unless bnd = caller_binding
vars.each do |s|
value = eval s.to_s, bnd
puts "#{s} = #{value.inspect}"
end
end
def test
a = 1
s = "hello"
var_dump :s, :a
end
test
return keyword, but it doesn't work on Ruby:# expected to see 1, 2 and 5; not 3 nor 4; and no errors eval "puts 1; puts 2; return; puts 3; puts 4" # => Error: unexpected return puts 5
return, end, exit, break, and I couldn't get success. exit doesn't raise errors, but then I don't get the 5.lambda do eval "puts 1; puts 2; return; puts 3; puts 4" end.call puts 5
return keyword can be used inside eval to get out from it successfully.