Skip to content

Instantly share code, notes, and snippets.

View greenplastik's full-sized avatar

Alexis M. greenplastik

View GitHub Profile
@greenplastik
greenplastik / test.rb
Created December 24, 2012 05:13
Problem with case statement with range and greater than comparisons
x=40
answer = case x
when x<1 then "400"
when 1...2 then "300"
when 2...4 then "250"
when 4...6 then "150"
when 6...8 then "125"
when 8...10 then "100"
when 10...12 then "92"
when 12...15 then "85"
# Let's say I have this the following array of strings that are usually dynamically created:
array = ["one", "two", "three", "four", "five"]
# I would like to to use this array to create the following hash, using the items from the array as the keys and then also using them to set the value by referencing another hash, as follows:
hsh = {"one" => some_other_hash[:one], "two" => some_other_hash[:two], "three" => some_other_hash[:three], "four" => some_other_hash[:four], "five" => some_other_hash[:five]}
# Rails: 3.0.0.beta3
# Ruby: ruby-head
# from routes.rb:
match '/calendar(/:year/:month)', :to => 'calendar#index', :defaults => { :year => Time.zone.now.year, :month => Time.zone.now.month }
# from calendar_helper.rb:
def month_link(date)
link_to(I18n.localize(date, :format => "%B"), {:controller => "calendar", :action => "index", :year => date.year, :month => date.month})
end
~/code/counselr[master]% rails g nifty:scaffold home
/Users/anmueller/.rvm/gems/ruby-1.9.1-p378@counselr/gems/thor-0.13.4/lib/thor/core_ext/hash_with_indifferent_access.rb:26:in `[]=': can't modify frozen hash (RuntimeError)
from /Users/anmueller/.rvm/gems/ruby-1.9.1-p378@counselr/gems/thor-0.13.4/lib/thor/core_ext/hash_with_indifferent_access.rb:26:in `[]='
from /Users/anmueller/.rvm/gems/ruby-1.9.1-p378@counselr/gems/nifty-generators-0.4.0/lib/generators/nifty/scaffold/scaffold_generator.rb:51:in `initialize'
from /Users/anmueller/.rvm/gems/ruby-1.9.1-p378@counselr/gems/thor-0.13.4/lib/thor/group.rb:36:in `new'
from /Users/anmueller/.rvm/gems/ruby-1.9.1-p378@counselr/gems/thor-0.13.4/lib/thor/group.rb:36:in `block in start'
from /Users/anmueller/.rvm/gems/ruby-1.9.1-p378@counselr/gems/thor-0.13.4/lib/thor/base.rb:378:in `start'
from /Users/anmueller/.rvm/gems/ruby-1.9.1-p378@counselr/gems/thor-0.13.4/lib/thor/group.rb:29:in `start'
from /Users/anmuelle
~% head `which ri`
#!/Users/anmueller/.rvm/rubies/ruby-1.8.7-p249/bin/ruby
ENV['GEM_HOME']=ENV['GEM_HOME'] || '/Users/anmueller/.rvm/gems/ruby-1.8.7-p249'
ENV['GEM_PATH']=ENV['GEM_PATH'] || '/Users/anmueller/.rvm/gems/ruby-1.8.7-p249:/Users/anmueller/.rvm/gems/ruby-1.8.7-p249%global'
ENV['PATH']='/Users/anmueller/.rvm/rubies/ruby-1.8.7-p249/bin:/Users/anmueller/.rvm/gems/ruby-1.8.7-p249/bin:' + ENV['PATH']
# usage:
#
# ri name...
#
# where name can be
Last login: Sun Apr 25 18:58:31 on ttys003
~% ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10.2.0]
~% rvm gemset gemdir
/Users/anmueller/.rvm/gems/ruby-1.8.7-p249
~% ri String
/Users/anmueller/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/rdoc/ri/ri_reader.rb:54:in `initialize': No such file or directory - /Users/anmueller/.rvm/rubies/ruby-1.8.7-p249/share/ri/1.8/system/String/cdesc-String.yaml (Errno::ENOENT)
from /Users/anmueller/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/rdoc/ri/ri_reader.rb:54:in `open'
from /Users/anmueller/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/rdoc/ri/ri_reader.rb:54:in `get_class'
from /Users/anmueller/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/rdoc/ri/ri_reader.rb:52:in `each'
ld: in /usr/local/lib/libz.1.dylib, file is not of required architecture
collect2: ld returned 1 exit status
make[1]: *** [../../../.ext/x86_64-darwin10.3.0/digest/md5.bundle] Error 1
make: *** [mkmain.sh] Error 1
Loading development environment (Rails 2.3.5)
>> Notifier.deliver_greeting
ArgumentError: wrong number of arguments (3 for 2)
from /Users/anmueller/.rvm/gems/ruby-1.8.7-p249/gems/openrain-action_mailer_tls-1.1.3/lib/smtp_tls.rb:8:in `check_auth_args'
from /Users/anmueller/.rvm/gems/ruby-1.8.7-p249/gems/openrain-action_mailer_tls-1.1.3/lib/smtp_tls.rb:8:in `do_start'
from /Users/anmueller/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/smtp.rb:525:in `start'
from /Users/anmueller/.rvm/gems/ruby-1.8.7-p249/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:682:in `perform_delivery_smtp'
from /Users/anmueller/.rvm/gems/ruby-1.8.7-p249/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:523:in `__send__'
from /Users/anmueller/.rvm/gems/ruby-1.8.7-p249/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:523:in `deliver!'
from /Users/anmueller/.rvm/gems/ruby-1.8.7-p249/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:395:in `method_missing'
apache2 @2.2.14 www/apache2
apr @1.3.9 devel/apr
apr-util @1.3.9 devel/apr-util
autoconf @2.65 devel/autoconf
autoconf213 @2.13 devel/autoconf213
automake @1.11.1 devel/automake
bzip2 @1.0.5 archivers/bzip2
cppunit @1.12.1 devel/cppunit
curl @7.19.7 net/curl
db46 @4.6.21 databases/db46
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by PostgreSQL configure 8.4.2, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ ./configure --enable-thread-safety --with-bonjour --with-gssapi --with-krb5 --with-openssl --with-libxml --with-libxslt --prefix=/usr/local/Cellar/postgresql/8.4.2 --disable-debug --with-python --with-perl ARCHFLAGS='-arch x86_64'
## --------- ##
## Platform. ##