-
The new lambda literal syntax is preferred in Ruby 1.9.
# BAD lambda = lambda { |a, b| a + b } # GOOD lambda = ->(a, b) { a + b }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):010:0> Symbol.all_symbols.map(&:to_s).grep /all_symbols/ | |
=> [] | |
irb(main):011:0> Symbol.all_symbols.map(&:to_s).grep /foocowbar/ | |
=> [] | |
irb(main):012:0> def foocowbar; nil; end | |
=> nil | |
irb(main):013:0> Symbol.all_symbols.map(&:to_s).grep /foocowbar/ | |
=> ["foocowbar"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Query | |
class Expression | |
attr_reader :field, :operator, :target | |
def initialize(field, operator, target) | |
@field, @operator, @target = field, operator, target | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This comes from here: https://github.com/sam/doubleshot/blob/master/lib/doubleshot/compiler.rb | |
# | |
# If you have JRuby 1.7.0, Java7, Maven and Bundler installed, you can reproduce the attached output like so: | |
# | |
# cd ~/src | |
# git clone git://github.com/sam/doubleshot.git | |
# cd doubleshot | |
# bundle install | |
# bin/doubleshot test --ci |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "must raise an exception if the file does not exist" do | |
Helper::tmp do |tmp| | |
assert_raises(Errno::ENOENT) do | |
Doubleshot::Compiler::Classpath.new.add(tmp + "asdf") | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.foo; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import java.util.Map; | |
import java.io.IOException; | |
public class Bar { | |
static final ObjectMapper mapper = new ObjectMapper(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.foo; | |
public class Bar { | |
public static int baz() { | |
return 1; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% # NOTE: The actual path is: views/forms/person.html.erb %> | |
<% # Or we can override the default rendering like so: %> | |
<h2>People Form</h2> | |
<% # By default the form-helper will POST to the current location %> | |
<% form do |form| %> | |
<table> | |
<tr><td>First Name:</td><td><%= form.field :first_name %></td></tr> | |
<tr><td>Last Name:</td><td><%= form.field :last_name %></td></tr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env jruby | |
require "rubygems" | |
require "active_support/hash_with_indifferent_access" | |
require "java" | |
require "benchmark" | |
SYMBOLS = [] | |
STRINGS = [] | |
GET_REPEAT = 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I get an HTTP 405: HTTP method GET is not supported by this URL | |
java_import javax.servlet.http.HttpServlet | |
class HelloWorld < HttpServlet | |
def process(request, response) | |
response.writer.println "Hello World!" | |
end | |
end |