Le site de doc pour ruby a fait peau neuve. C'est jolie et clair j'aime bien :)
Vu sur o'reilly
Ruby (le langage de programmation) et Rails. (made in Toulouse)
object = nil
if(object)
puts 'on ne voit pas ce message'
end
Si un objet et nil, le test est false.
Object object = null;
if(object!=null) {
System.out.println("on ne voit pas ce message");
}
>ruby -r config/environment -e 'print Object.constants.sort.join(", ")'
Résultat:
ARGF, ARGV, ActionController, ActionMailer, ActionPack, ActionView, ActionWebSer vice, ActiveRecord, ActiveSupport, ArgumentError, Array, BREAKPOINT_SERVER_PORT, Base64, BasicSocket, Benchmark, Bignum, Binding, Buffering, Builder, CGI, CGIMe thods, CROSS_COMPILING, Class, ClassInheritableAttributes, Comparable, Condition Variable, Config, Continuation, Controllers, DRb, DRbIdConv, DRbObject, DRbUndum ped, Data, Date, DateTime, Delegater, Delegator, Dependencies, Deprecated, Diges t, Dir, ENV, EOFError, ERB, Enumerable, Errno, Exception, FALSE, FalseClass, Fcn tl, File, FileTest, FileUtils, FireRuby, Fixnum, Float, FloatDomainError, Forwar dable, GC, Gem, HTML, Hash, HashWithIndifferentAccess, IO, IOError, IPSocket, IP socket, IndexError, Inflector, Integer, Interrupt, Kconv, Kernel, LoadError, Loc alJumpError, Logger, MailHelper, Marshal, MatchData, MatchingData, Math, Method, MissingSourceFile, Module, Mutex, Mutex_m, NIL, NKF, NQXML, NameError, Net, Nil Class, NoMemoryError, NoMethodError, NotImplementedError, Numeric, Object, Objec tSpace, Observable, OpenSSL, OrderedOptions, PLATFORM, PStore, ParseDate, ParseE rror, Pathname, Precision, Proc, Process, Queue, RAILS_CONNECTION_ADAPTERS, RAIL S_DEFAULT_LOGGER, RAILS_ENV, RAILS_ROOT, RAILTIES_PATH, RELEASE_DATE, REXML, RUB Y_PLATFORM, RUBY_RELEASE_DATE, RUBY_VERSION, Racc, Rails, Range, RangeError, Rat ional, Regexp, RegexpError, RuntimeError, SOAP, STDERR, STDIN, STDOUT, ScanError , ScriptError, SecurityError, Set, Signal, SignalException, SimpleDelegater, Sim pleDelegator, SingleForwardable, Singleton, SizedQueue, Socket, SocketError, Sor tedSet, StandardError, String, StringIO, StringInput, StringOutput, StringScanne r, Struct, Symbol, SyntaxError, SystemCallError, SystemExit, SystemStackError, T CPServer, TCPSocket, TCPserver, TCPsocket, TMail, TOPLEVEL_BINDING, TRUE, Text, Thread, ThreadError, ThreadGroup, Time, TimeZone, Timeout, TimeoutError, Transac tion, TrueClass, TypeError, UDPSocket, UDPsocket, URI, UnboundMethod, VERSION, W in32API, XML, XMLEncoding, XMLParser, XMLParserError, XMLRPC, XSD, XmlSimple, YA ML, ZeroDivisionError, Zlib
C:\developpement\workspaces\workspaceRuby\projet>ruby script/about About your application's environment Ruby version 1.8.2 (i386-mswin32) RubyGems version 0.8.10 Rails version 1.0.0 Active Record version 1.13.2 Action Pack version 1.11.2 Action Web Service version 1.0.0 Action Mailer version 1.1.5 Active Support version 1.2.5 Application root C:/developpement/workspaces/workspaceRuby/projet Environment development Database adapter mysql
require "rubygems"
require_gem "activerecord"
# probleme de mysql
# http://jeroen.concept-q.biz/files/
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "mysql.machine",
:username => "user",
:password => "password",
:database => "dotproject")
class TaskLog < ActiveRecord::Base
set_table_name "task_log"
set_primary_key "task_log_id"
end
task_logs = TaskLog.find(:all, :conditions => "task_log_creator = '49'")
for task_log in task_logs
puts task_log.task_log_id
end
Mysql::Error: Lost connection to MySQL server during query: SELECT * FROM task_log WHERE (task_log_creator = '49') (ActiveRecord::StatementInvalid)
before_filter :set_charset
def set_charset
@headers["Content-Type"] = "text/html; charset=iso-8859-1"
end
Quelques liens interessants sur le sujet: