Ruby is very flexible and will allow you to butcher all of the good things about its syntax in a large variety of ways. Here we'll present, by example, how to keep things nice.
foo.bar(a)
{15:18}[jruby-1.6.4]~/code/ruby/niceogiri@master✗✗✗ ben% bundle install | |
StreamReader.java:98:in `checkPrintable': unacceptable character '' (0x8B) special characters are not allowed | |
in "<reader>", position 415 | |
from StreamReader.java:191:in `update' | |
from StreamReader.java:63:in `<init>' | |
from PsychParser.java:106:in `parse' | |
from PsychParser$i$1$0$parse.gen:65535:in `call' | |
from CachingCallSite.java:167:in `call' | |
from CallOneArgNode.java:57:in `interpret' | |
from NewlineNode.java:104:in `interpret' |
{17:27}[rbx-head]~/code/VoIP/adhearsion/punchblock@develop✗✗✗ ben% gem install nokogiri | |
Invalid gemspec in [/Users/ben/Developer/.rvm/gems/rbx-head/specifications/looksee-1.0.3.gemspec]: Illformed requirement ["#<YAML::Syck::DefaultKey:0x49d0c> 0.3.0"] | |
Invalid gemspec in [/Users/ben/Developer/.rvm/gems/rbx-head/specifications/looksee-1.0.3.gemspec]: Illformed requirement ["#<YAML::Syck::DefaultKey:0x49d0c> 0.3.0"] | |
Building native extensions. This could take a while... | |
Successfully installed nokogiri-1.5.0 | |
1 gem installed | |
{17:27}[rbx-head]~/code/VoIP/adhearsion/punchblock@develop✗✗✗ ben% irb | |
Invalid gemspec in [/Users/ben/Developer/.rvm/gems/rbx-head/specifications/looksee-1.0.3.gemspec]: Illformed requirement ["#<YAML::Syck::DefaultKey:0x49d0c> 0.3.0"] | |
'looksee/shortcuts' is deprecated; please require 'looksee' instead. | |
>> require 'nokogiri' |
def factorial(number) | |
number.downto(1).inject(:*) | |
end |
* { :ruby => ruby-1.9.2-p290 } | |
/Users/ben/Developer/.rvm/gems/ruby-1.9.2-p290/bin/bundle exec rvm ruby-1.9.2-p290 ruby /Users/ben/Developer/.rvm/gems/ruby-1.9.2-p290/bin/rspec spec/punchblock/client_spec.rb | |
Using /Users/ben/Developer/.rvm/gems/ruby-1.9.2-p290 | |
No examples were matched by {:focus=>true}, running all | |
Punchblock::Client | |
should handle connection events | |
event_queue | |
should be a kind of Queue | |
connection |
# line 1 "lib/ruby_ami/lexer.rl.rb" | |
module RubyAMI | |
class Lexer | |
BUFFER_SIZE = 128.kilobytes unless defined? BUFFER_SIZE | |
## | |
# IMPORTANT! See method documentation for adjust_pointers! | |
# |
>> a = ["12068180,LC,Q8,10.396,7455,2.617,3.779,-0.388,0.008,4"] | |
=> ["12068180,LC,Q8,10.396,7455,2.617,3.779,-0.388,0.008,4"] | |
>> a.first[-1] | |
=> "4" | |
>> a.delete_if { |star| star[-1] == '4' } | |
=> [] | |
>> a | |
=> [] |
>> a = ["12068180,LC,Q8,10.396,7455,2.617,3.779,-0.388,0.008,4"] | |
=> ["12068180,LC,Q8,10.396,7455,2.617,3.779,-0.388,0.008,4"] | |
>> a.first[-1] | |
=> "4" | |
>> a.delete_if { |star| star[-1] == '4' } | |
=> [] | |
>> a | |
=> [] |
# http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html | |
# Write a program that prints the numbers from 1 to 100. | |
# But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". | |
# For numbers which are multiples of both three and five print "FizzBuzz". | |
(1..100).each do |i| | |
res = if i % 3 == 0 && i % 5 == 0 | |
"FizzBuzz" |
Failures: | |
1) A NumericalString comparing against a regular expression works | |
Failure/Error: %r|^\d+$|.should === numerical_string_for("027316287") | |
PrimitiveFailure: | |
Regexp#search_region primitive failed | |
# kernel/bootstrap/regexp.rb:21:in `search_region' | |
# kernel/common/regexp.rb:283:in `match_from' | |
# kernel/common/regexp.rb:207:in `===' | |
# ./spec/adhearsion/numerical_string_spec.rb:34:in `__script__' |