| | 316 | |
| | 317 | =begin |
| | 318 | require 'rubygems' |
| | 319 | require 'active_support' |
| | 320 | p 1.second # 1 second |
| | 321 | p 2.minutes + 30.seconds # 150 seconds |
| | 322 | p 4.hours + 32.minutes # 16320 seconds |
| | 323 | p 10.months + 10.days # 10 months and 10 days |
| | 324 | p 1.week # 7 days |
| | 325 | p 1.fortnight # 14 days |
| | 326 | p 1.month # 1 month |
| | 327 | p 1.year # 1 year |
| | 328 | |
| | 329 | p Time.now # Thu Feb 07 15:16:29 +0900 2008 |
| | 330 | p 10.minutes.ago # Thu Feb 07 15:06:45 +0900 2008 |
| | 331 | p 20.minutes.from_now # Thu Feb 07 15:37:05 +0900 2008 |
| | 332 | p 7.days.ago(Time.mktime(2006,1,1)) # Sun Dec 25 00:00:00 +0900 2005 |
| | 333 | =end |
| | 334 | |
| | 335 | =begin |
| | 336 | require 'rubygems' |
| | 337 | require 'active_support' |
| | 338 | p 14.bytes # 14 |
| | 339 | p 2.kilobytes # 2048 |
| | 340 | p 256.megabytes # 268435456 |
| | 341 | p 1.gigabytes # 1073741824 |
| | 342 | p 1.gigabyte.class # Bignum |
| | 343 | p 2.terabytes # 2199023255552 |
| | 344 | p 512.petabytes + 1.exabyte # 1729382256910270464 |
| | 345 | =end |
| | 346 | |
| | 347 | =begin |
| | 348 | require 'rubygems' |
| | 349 | require 'active_support' |
| | 350 | p now = Time.mktime(2007, 6, 5, 4, 32) # Tue Jun 05 04:32:00 +0900 2007 |
| | 351 | p (now + 3.days).midnight # Fri Jun 08 00:00:00 +0900 2007 |
| | 352 | p now.next_month.beginning_of_month # Sun Jul 01 00:00:00 +0900 2007 |
| | 353 | p now.end_of_month # Sat Jun 30 23:59:59 +0900 2007 |
| | 354 | p Time.days_in_month(2, 2000) # 29 |
| | 355 | p now.seconds_since_midnight # 16320.0 |
| | 356 | p now.change(:year=>2005, :month=>6) # Sun Jun 05 04:32:00 +0900 2005 |
| | 357 | p now.advance(:months=>-1, :days=>3) # Tue May 08 04:32:00 +0900 2007 |
| | 358 | p now.months_ago(10) # Sat Aug 05 04:32:00 +0900 2006 |
| | 359 | p now.last_year # Mon Jun 05 04:32:00 +0900 2006 |
| | 360 | p now.next_year # Thu Jun 05 04:32:00 +0900 2008 |
| | 361 | p now.last_month # Sat May 05 04:32:00 +0900 2007 |
| | 362 | p now.next_month # Thu Jul 05 04:32:00 +0900 2007 |
| | 363 | p now.beginning_of_week # Mon Jun 04 00:00:00 +0900 2007 |
| | 364 | p now.next_week(:friday) # Fri Jun 15 00:00:00 +0900 2007 |
| | 365 | p now.beginning_of_day # Tue Jun 05 00:00:00 +0900 2007 |
| | 366 | p now.midnight # Tue Jun 05 00:00:00 +0900 2007 |
| | 367 | p now.beginning_of_month # Fri Jun 01 00:00:00 +0900 2007 |
| | 368 | p now.end_of_month # Sat Jun 30 23:59:59 +0900 2007 |
| | 369 | p now.beginning_of_quarter # Sun Apr 01 00:00:00 +0900 2007 |
| | 370 | p now.beginning_of_year # Mon Jan 01 00:00:00 +0900 2007 |
| | 371 | p now.yesterday # Mon Jun 04 04:32:00 +0900 2007 |
| | 372 | p now.tomorrow # Wed Jun 06 04:32:00 +0900 2007 |
| | 373 | =end |
| | 374 | |
| | 375 | =begin |
| | 376 | class Symbol |
| | 377 | def to_proc |
| | 378 | Proc.new { |obj, *args| obj.send(self, *args) } |
| | 379 | end |
| | 380 | end |
| | 381 | =end |
| | 382 | |
| | 383 | =begin |
| | 384 | array = [1,2,3] |
| | 385 | p array.map{ |i| i.to_s } # ["1", "2", "3"] |
| | 386 | =end |
| | 387 | |
| | 388 | =begin |
| | 389 | require 'rubygems' |
| | 390 | require 'active_support' |
| | 391 | array = [1,2,3] |
| | 392 | array.map(&:to_s) |
| | 393 | p array # [1, 2, 3] |
| | 394 | =end |
| | 395 | |
| | 396 | =begin |
| | 397 | require 'rubygems' |
| | 398 | require 'active_support' |
| | 399 | array = [1,2,3] |
| | 400 | block = :to_s |
| | 401 | p array.map(&block) |
| | 402 | =end |
| | 403 | |
| | 404 | =begin |
| | 405 | require 'rubygems' |
| | 406 | require 'active_support' |
| | 407 | array = [1,2,3] |
| | 408 | block = :to_s |
| | 409 | p array.map{ |obj| obj.send(:to_s)} |
| | 410 | =end |
| | 411 | |
| | 412 | =begin |
| | 413 | require 'rubygems' |
| | 414 | require 'active_support' |
| | 415 | array = [1,2,3] |
| | 416 | p array.map{ |obj| obj.to_s } |
| | 417 | =end |
| | 418 | |
| | 419 | =begin |
| | 420 | members = Member.find(:all) |
| | 421 | ids = members.map(&:id) |
| | 422 | names = members.map(&:name) |
| | 423 | =end |