writing destructive string methods in Ruby
Example:
def decapitalize! replace (self.reverse.chop + self.reverse.last.downcase).reverse end def decapitalize dup.decapitalize! end
TextSnippets > deckard > rails
2807 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
def decapitalize! replace (self.reverse.chop + self.reverse.last.downcase).reverse end def decapitalize dup.decapitalize! end
myresource_path(:id => myId, :extra_param => extraId, :extra_param2 => blah)
myresource/myId?extra_param=extraId&extra_param2=blah
# KNOWN_TAG = XSD::NS::KNOWN_TAG.dup.update( # SOAP::EnvelopeNamespace => 'env' # ) # Replaced with code from http://dev.ctor.org/soap4r/ticket/433 KNOWN_TAG = { XSD::Namespace => 'xsd', XSD::InstanceNamespace => 'xsi', SOAP::EnvelopeNamespace => 'env' }
rake rails:freeze:edge TAG=rel_1-2-3
http://dev.rubyonrails.org/svn/rails/plugins/legacy/
>> extend ERB::Util => #<Object:0x2572f68> >> h('<b>blahblah</b>') => "<b>blahblah</b>"
flash.now[:warning] = "You must be the group admin (and logged in) to edit."
ENV['HOME'] = '/home/billy'
- log "Changing user to #{user}." - Process::UID.change_privilege(Etc.getpwnam(user).uid) + log "Changing user to #{user}." + getpwnam = Etc.getpwnam(user) + Process::UID.change_privilege(getpwnam.uid) + ENV['HOME'] = getpwnam.dir
config.logger = Logger.new("#{RAILS_ROOT}/log/#{ENV['RAILS_ENV']}.log", 50, 5242880)
def set_focus_to_id(id) javascript_tag("$('#{id}').focus()"); end
<%= set_focus_to_id 'user_login' %>
request.env["HTTP_USER_AGENT"]
def toggle_showall render(:update) do |page| page[:fb_content].replace_html "just text? ripoff!" page[:flash_box].visual_effect :blind_down, :duration => 0.25 end end
page[:fb_content]
page[:fb_content].replace_html "just text? ripoff!"
page[:fb_content].replace_html :partial => "shared/some_partial"
page[:flash_box].visual_effect :blind_down, :duration => 0.25
include ActionView::Helpers::DateHelper
def original_control_handler [misc methods and other things] [done normally in this controller] render :update do |page| page.replace_html 'calling_element_id', :partial => 'updated_template' page.helper 'helper_id', :helper_options => 'go here' end end
... page.replace_html 'element_to_update', "this string goes in element"
page.replace 'element2_to_update', (link_to_remote "link_text", {:url => dest, :method => :get, :id => 'element2_to_update')
?chapter=9&sort_by=created_at&sort_dir=desc
:with => "'chapter='+ encodeURIComponent(value)+'&sort_by=#{@sort_by}&sort_dir=#{@sort_dir}&='", :update => 'list_items'
<%= javascript_include_tag "prototype" %>
<%= link_to_function @toggle_text, remote_function(:url => watch_lists_path, :method => :post, :with => "Form.serialize('watch_form')", :update => 'follow_anchor'), :id => 'follow_anchor' %>
def create @watch_list = WatchList.new(params[:watch_list]) if @watch_list.toggle render(:text => @watch_list.toggle_text) else render(:text => 'We couldn''t add this book to your Watch List. Please contact us for help.') end end
logger = Logger.new(STDOUT) logger.debug ("title: #{@attr.get('title')}") logger.debug("small_image: #{@images.search_and_convert('smallimage')}")
debug(@instance_var.pretty_inspect)
mysql_config --socket sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
$HTTP["host"] =~ "(www\.)?(hatepad|sexymsg)\.(com|net)" { server.document-root = base + "/domains/sexymsg.com/web/public/" server.error-handler-404 = "/dispatch.fcgi" fastcgi.server = ( ".fcgi" => ( "localhost" => ( "socket" => base + "/var/run/sexymsg-0.socket" ) ) ) }
kill -9 <lighttpd PID> . ~/etc/rc.d/lighttpd.sh start