Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9226

Show
Ignore:
Timestamp:
04/05/08 03:52:58 (3 months ago)
Author:
pratik
Message:

Improve documentation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r9212 r9226  
    11*SVN* 
     2 
     3* Improve documentation. [Xavier Noria, leethal, jerome] 
    24 
    35* Ensure RJS redirect_to doesn't html-escapes string argument. Closes #8546 [josh, eventualbuddha, Pratik] 
  • trunk/actionpack/lib/action_controller/routing.rb

    r9115 r9226  
    4848  #   :action     maps to an action with your controllers 
    4949  # 
    50   # Other names simply map to a parameter as in the case of +:id+
     50  # Other names simply map to a parameter as in the case of <tt>:id</tt>
    5151  # 
    5252  # == Route priority 
     
    8383  # This means visiting '/' would invoke the blog controller. 
    8484  # 
    85   # More formally, you can define defaults in a route with the +:defaults+ key. 
     85  # More formally, you can define defaults in a route with the <tt>:defaults</tt> key. 
    8686  # 
    8787  #   map.connect ':controller/:action/:id', :action => 'show', :defaults => { :page => 'Dashboard' } 
  • trunk/actionpack/lib/action_view/helpers/prototype_helper.rb

    r9212 r9226  
    717717          #   # element with ID 'content'. 
    718718          #   # Generates: new Insertion.Before("content", "-- Contents of 'navigation' partial --"); 
    719           #   insert_html :before, 'content', :partial => 'navigation' 
     719          #   page.insert_html :before, 'content', :partial => 'navigation' 
    720720          # 
    721721          #   # Add a list item to the bottom of the <ul> with ID 'list'. 
    722722          #   # Generates: new Insertion.Bottom("list", "<li>Last item</li>"); 
    723           #   insert_html :bottom, 'list', '<li>Last item</li>' 
     723          #   page.insert_html :bottom, 'list', '<li>Last item</li>' 
    724724          # 
    725725          def insert_html(position, id, *options_for_render) 
     
    736736          #   # 'person' partial for the appropriate object. 
    737737          #   # Generates:  Element.update("person-45", "-- Contents of 'person' partial --"); 
    738           #   replace_html 'person-45', :partial => 'person', :object => @person 
     738          #   page.replace_html 'person-45', :partial => 'person', :object => @person 
    739739          # 
    740740          def replace_html(id, *options_for_render) 
     
    750750          #   # Replace the DOM element having ID 'person-45' with the 
    751751          #   # 'person' partial for the appropriate object. 
    752           #   replace 'person-45', :partial => 'person', :object => @person 
     752          #   page.replace 'person-45', :partial => 'person', :object => @person 
    753753          # 
    754754          # This allows the same partial that is used for the +insert_html+ to 
  • trunk/actionpack/lib/action_view/helpers/url_helper.rb

    r9034 r9226  
    8787      # url_for. It's also possible to pass a string instead 
    8888      # of an options hash to get a link tag that uses the value of the string as the 
    89       # href for the link, or use +:back+ to link to the referrer - a JavaScript back 
     89      # href for the link, or use <tt>:back</tt> to link to the referrer - a JavaScript back 
    9090      # link will be used in place of a referrer if none exists. If nil is passed as 
    9191      # a name, the link itself will become the name. 
  • trunk/activerecord/CHANGELOG

    r9202 r9226  
    11*SVN* 
     2 
     3* Improve documentation. [Xavier Noria, Jack Danger Canty, leethal] 
    24 
    35* Tweak ActiveRecord::Base#to_json to include a root value in the returned hash: {"post": {"title": ...}} [rick] 
  • trunk/activerecord/lib/active_record/associations.rb

    r9095 r9226  
    137137    #   #others.size                      |   X   |    X     |    X 
    138138    #   #others.length                    |   X   |    X     |    X 
    139     #   #others.count                     |       |    X     |    X 
     139    #   #others.count                     |   X   |    X     |    X 
    140140    #   #others.sum(args*,&block)         |   X   |    X     |    X 
    141141    #   #others.empty?                    |   X   |    X     |    X 
     
    151151    # == Cardinality and associations 
    152152    # 
    153     # ActiveRecord associations can be used to describe relations with one-to-one, one-to-many 
    154     # and many-to-many cardinality. Each model uses an association to describe its role in 
    155     # the relation. In each case, the +belongs_to+ association is used in the model that has 
     153    # ActiveRecord associations can be used to describe one-to-one, one-to-many and many-to-many 
     154    # relationships between models. Each model uses an association to describe its role in 
     155    # the relation. The +belongs_to+ association is always used in the model that has 
    156156    # the foreign key. 
    157157    # 
  • trunk/activerecord/lib/active_record/associations/association_proxy.rb

    r9084 r9226  
    11module ActiveRecord 
    22  module Associations 
     3    # This is the root class of all association proxies: 
     4    # 
     5    #   AssociationProxy 
     6    #     BelongsToAssociation 
     7    #       HasOneAssociation 
     8    #     BelongsToPolymorphicAssociation 
     9    #     AssociationCollection 
     10    #       HasManyAssociation 
     11    #       HasAndBelongsToManyAssociation 
     12    #     HasManyThroughAssociation 
     13    #       HasOneThroughAssociation 
     14    # 
     15    # Association proxies in Active Record are middlemen between the object that 
     16    # holds the association, known as the <tt>@owner</tt>, and the actual associated 
     17    # object, known as the <tt>@target</tt>. The kind of association any proxy is 
     18    # about is available in <tt>@reflection</tt>. That's an instance of the class 
     19    # ActiveRecord::Reflection::AssociationReflection. 
     20    # 
     21    # For example, given 
     22    # 
     23    #   class Blog < ActiveRecord::Base 
     24    #     has_many :posts 
     25    #   end 
     26    # 
     27    #   blog = Blog.find(:first) 
     28    # 
     29    # the association proxy in <tt>blog.posts</tt> has the object in +blog+ as 
     30    # <tt>@owner</tt>, the collection of its posts as <tt>@target</tt>, and 
     31    # the <tt>@reflection</tt> object represents a <tt>:has_many</tt> macro. 
     32    # 
     33    # This class has most of the basic instance methods removed, and delegates 
     34    # unknown methods to <tt>@target</tt> via <tt>method_missing</tt>. As a 
     35    # corner case, it even removes the +class+ method and that's why you get 
     36    # 
     37    #   blog.posts.class # => Array 
     38    # 
     39    # though the object behind <tt>blog.posts</tt> is not an Array, but an 
     40    # ActiveRecord::Associations::HasManyAssociation. 
     41    # 
     42    # The <tt>@target</tt> object is not loaded until needed. For example, 
     43    # 
     44    #   blog.posts.count 
     45    # 
     46    # is computed directly through SQL and does not trigger by itself the 
     47    # instantiation of the actual post records. 
    348    class AssociationProxy #:nodoc: 
    449      alias_method :proxy_respond_to?, :respond_to? 
  • trunk/activerecord/lib/active_record/base.rb

    r9157 r9226  
    191191  # 
    192192  #   Student.find(:all, :conditions => { :grade => 9..12 }) 
     193  # 
     194  # An array may be used in the hash to use the SQL IN operator: 
     195  # 
     196  #   Student.find(:all, :conditions => { :grade => [9,11,12] }) 
    193197  # 
    194198  # == Overwriting default accessors 
     
    489493      #   Person.find(:all) # returns an array of objects for all the rows fetched by SELECT * FROM people 
    490494      #   Person.find(:all, :conditions => [ "category IN (?)", categories], :limit => 50) 
     495      #   Person.find(:all, :conditions => { :friends => ["Bob", "Steve", "Fred"] } 
    491496      #   Person.find(:all, :offset => 10, :limit => 10) 
    492497      #   Person.find(:all, :include => [ :account, :friends ]) 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

    r9122 r9226  
    162162      # 
    163163      # The index will be named after the table and the first column name, 
    164       # unless you pass +:name+ as an option. 
     164      # unless you pass <tt>:name</tt> as an option. 
    165165      # 
    166166      # When creating an index on multiple columns, the first column is used as a name 
    167167      # for the index. For example, when you specify an index on two columns 
    168       # [+:first+, +:last+], the DBMS creates an index for both columns as well as an 
    169       # index for the first column +:first+. Using just the first name for this index 
     168      # [<tt>:first</tt>, <tt>:last</tt>], the DBMS creates an index for both columns as well as an 
     169      # index for the first column <tt>:first</tt>. Using just the first name for this index 
    170170      # makes sense, because you will never have to create a singular index with this 
    171171      # name. 
  • trunk/activerecord/lib/active_record/reflection.rb

    r8571 r9226  
    7777      end 
    7878 
    79       # Returns the name of the macro, so it would return :balance for "composed_of :balance, :class_name => 'Money'" or 
    80       # :clients for "has_many :clients"
     79      # Returns the name of the macro.  For example, <tt>composed_of :balance, :class_name => 'Money'</tt> will return 
     80      # <tt>:balance</tt> or for <tt>has_many :clients</tt> it will return <tt>:clients</tt>
    8181      def name 
    8282        @name 
    8383      end 
    8484 
    85       # Returns the type of the macro, so it would return :composed_of for 
    86       # "composed_of :balance, :class_name => 'Money'" or :has_many for "has_many :clients"
     85      # Returns the macro type. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> will return <tt>:composed_of</tt> 
     86      # or for <tt>has_many :clients</tt> will return <tt>:has_many</tt>
    8787      def macro 
    8888        @macro 
    8989      end 
    9090 
    91       # Returns the hash of options used for the macro, so it would return { :class_name => "Money" } for 
    92       # "composed_of :balance, :class_name => 'Money'" or {} for "has_many :clients". 
     91      # Returns the hash of options used for the macro.  For example, it would return <tt>{ :class_name => "Money" }</tt> for 
     92      # <tt>composed_of :balance, :class_name => 'Money'</tt> or +{}+ for <tt>has_many :clients</tt>. 
     93 
    9394      def options 
    9495        @options 
    9596      end 
    9697 
    97       # Returns the class for the macro, so "composed_of :balance, :class_name => 'Money'" returns the Money class and 
    98       # "has_many :clients" returns the Client class. 
     98      # Returns the class for the macro.  For example, <tt>composed_of :balance, :class_name => 'Money'</tt> returns the +Money+ 
     99      # class and <tt>has_many :clients</tt> returns the +Client+ class. 
    99100      def klass 
    100101        @klass ||= class_name.constantize 
    101102      end 
    102103 
     104      # Returns the class name for the macro.  For example, <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>'Money'</tt> 
     105      # and <tt>has_many :clients</tt> returns <tt>'Client'</tt>. 
    103106      def class_name 
    104107        @class_name ||= options[:class_name] || derive_class_name 
    105108      end 
    106109 
     110      # Returns +true+ if +self+ and +other_aggregation+ have the same +name+ attribute, +active_record+ attribute, 
     111      # and +other_aggregation+ has an options hash assigned to it. 
    107112      def ==(other_aggregation) 
    108113        name == other_aggregation.name && other_aggregation.options && active_record == other_aggregation.active_record 
  • trunk/activerecord/lib/active_record/transactions.rb

    r8484 r9226  
    2929    # This example will only take money from David and give to Mary if neither +withdrawal+ nor +deposit+ raises an exception. 
    3030    # Exceptions will force a ROLLBACK that returns the database to the state before the transaction was begun. Be aware, though, 
    31     # that the objects by default will _not_ have their instance data returned to their pre-transactional state. 
     31    # that the objects will _not_ have their instance data returned to their pre-transactional state. 
    3232    # 
    3333    # == Different ActiveRecord classes in a single transaction 
  • trunk/activerecord/lib/active_record/validations.rb

    r9168 r9226  
    724724      # Configuration options: 
    725725      # * <tt>in</tt> - An enumerable object of available items 
    726       # * <tt>message</tt> - Specifies a customer error message (default is: "is not included in the list") 
     726      # * <tt>message</tt> - Specifies a custom error message (default is: "is not included in the list") 
    727727      # * <tt>allow_nil</tt> - If set to true, skips this validation if the attribute is null (default is: false) 
    728728      # * <tt>allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is: false) 
     
    756756      # Configuration options: 
    757757      # * <tt>in</tt> - An enumerable object of items that the value shouldn't be part of 
    758       # * <tt>message</tt> - Specifies a customer error message (default is: "is reserved") 
     758      # * <tt>message</tt> - Specifies a custom error message (default is: "is reserved") 
    759759      # * <tt>allow_nil</tt> - If set to true, skips this validation if the attribute is null (default is: false) 
    760760      # * <tt>allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is: false) 
  • trunk/activerecord/README

    r8371 r9226  
    103103 
    104104 
    105 * Transaction support on both a database and object level. The latter is implemented  
    106   by using Transaction::Simple[http://railsmanual.com/module/Transaction::Simple] 
    107  
    108     # Just database transaction 
     105* Transactions 
     106 
     107    # Database transaction 
    109108    Account.transaction do 
    110       david.withdrawal(100) 
    111       mary.deposit(100) 
    112     end 
    113  
    114     # Database and object transaction 
    115     Account.transaction(david, mary) do 
    116109      david.withdrawal(100) 
    117110      mary.deposit(100) 
  • trunk/activeresource/CHANGELOG

    r9114 r9226  
    11*SVN* 
     2 
     3* Improve documentation. [Xavier Noria] 
    24 
    35* Fixed that to_param should be used and honored instead of hardcoding the id #11406 [gspiers] 
  • trunk/activesupport/lib/active_support/core_ext/array/access.rb

    r8224 r9226  
    44      # Makes it easier to access parts of an array. 
    55      module Access 
    6         # Returns the remaining of the array from the +position+. 
     6        # Returns the tail of the array from +position+. 
    77        # 
    8         # Examples:  
    98        #   %w( a b c d ).from(0)  # => %w( a b c d ) 
    109        #   %w( a b c d ).from(2)  # => %w( c d ) 
     
    1413        end 
    1514         
    16         # Returns the beginning of the array up to the +position+. 
     15        # Returns the beginning of the array up to +position+. 
    1716        # 
    18         # Examples:  
    1917        #   %w( a b c d ).to(0)  # => %w( a ) 
    2018        #   %w( a b c d ).to(2)  # => %w( a b c ) 
  • trunk/activesupport/lib/active_support/core_ext/array/conversions.rb

    r9093 r9226  
    3131        end 
    3232 
    33         # Converts an array into a string suitable for use as a URL query string, using the given <tt>key</tt> as the 
    34         # param name. 
    35         # 
    36         # Example: 
     33        # Converts an array into a string suitable for use as a URL query string, 
     34        # using the given +key+ as the param name. 
    3735        # 
    3836        #   ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding" 
     
    8179        # 
    8280        # Root children have as node name the one of the root singularized. 
    83         # 
    84         # Example: 
    8581        # 
    8682        #   [{:foo => 1, :bar => 2}, {:baz => 3}].to_xml 
  • trunk/activesupport/lib/active_support/core_ext/array/extract_options.rb

    r7217 r9226  
    33    module Array #:nodoc: 
    44      module ExtractOptions 
    5         # Extract options from a set of arguments. Removes and returns the last element in the array if it's a hash, otherwise returns a blank hash. 
     5        # Extracts options from a set of arguments. Removes and returns the last 
     6        # element in the array if it's a hash, otherwise returns a blank hash. 
    67        # 
    78        #   def options(*args) 
  • trunk/activesupport/lib/active_support/core_ext/array/grouping.rb

    r9093 r9226  
    55    module Array #:nodoc: 
    66      module Grouping 
    7         # Iterate over an array in groups of a certain size, padding any remaining  
    8         # slots with specified value (<tt>nil</tt> by default) unless it is 
    9         # <tt>false</tt>. 
    10         #  
    11         # Examples: 
     7        # Iterates over the array in groups of size +number+, padding any remaining  
     8        # slots with +fill_with+ unless it is +false+. 
    129        #  
    1310        #   %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g} 
     
    4340        end 
    4441 
    45         # Divide the array into one or more subarrays based on a delimiting +value+ 
     42        # Divides the array into one or more subarrays based on a delimiting +value+ 
    4643        # or the result of an optional block. 
    47         # 
    48         # Examples: 
    4944        # 
    5045        #   [1, 2, 3, 4, 5].split(3)                # => [[1, 2], [4, 5]] 
  • trunk/activesupport/lib/active_support/core_ext/array/random_access.rb

    r7490 r9226  
    33    module Array #:nodoc: 
    44      module RandomAccess 
    5         # Return a random element from the array. 
     5        # Returns a random element from the array. 
    66        def rand 
    77          self[Kernel.rand(length)] 
  • trunk/activesupport/lib/active_support/core_ext/blank.rb

    r9093 r9226  
    11class Object 
    22  # An object is blank if it's false, empty, or a whitespace string. 
    3   # For example, "", "   ", nil, [], and {} are blank. 
     3  # For example, "", "   ", +nil+, [], and {} are blank. 
    44  # 
    55  # This simplifies 
     6  # 
    67  #   if !address.nil? && !address.empty? 
     8  # 
    79  # to 
     10  # 
    811  #   if !address.blank? 
    912  def blank? 
  • trunk/activesupport/lib/active_support/core_ext/class/removal.rb

    r9093 r9226  
    11class Class #:nodoc: 
    22   
    3   # Will unassociate the class with its subclasses as well as uninitializing the subclasses themselves. 
    4   # >> Integer.remove_subclasses 
    5   # => [Bignum, Fixnum] 
    6   # >> Fixnum 
    7   # NameError: uninitialized constant Fixnum 
     3  # Unassociates the class with its subclasses and removes the subclasses 
     4  # themselves. 
     5  # 
     6  #   Integer.remove_subclasses # => [Bignum, Fixnum] 
     7  #   Fixnum                    # => NameError: uninitialized constant Fixnum 
    88  def remove_subclasses 
    99    Object.remove_subclasses_of(self) 
    1010  end 
    1111 
    12   # Returns a list of classes that inherit from this class in an array. 
    13   # Example: Integer.subclasses => ["Bignum", "Fixnum"] 
     12  # Returns an array with the names of the subclasses of +self+ as strings. 
     13  # 
     14  #   Integer.subclasses # => ["Bignum", "Fixnum"] 
    1415  def subclasses 
    1516    Object.subclasses_of(self).map { |o| o.to_s } 
    1617  end 
    1718 
    18   # Allows you to remove individual subclasses or a selection of subclasses from a class without removing all of them. 
     19  # Removes the classes in +klasses+ from their parent module. 
     20  # 
     21  # Ordinary classes belong to some module via a constant. This method computes 
     22  # that constant name from the class name and removes it from the module it 
     23  # belongs to. 
     24  # 
     25  #   Object.remove_class(Integer) # => [Integer] 
     26  #   Integer                      # => NameError: uninitialized constant Integer 
     27  # 
     28  # Take into account that in general the class object could be still stored 
     29  # somewhere else. 
     30  # 
     31  #   i = Integer                  # => Integer 
     32  #   Object.remove_class(Integer) # => [Integer] 
     33  #   Integer                      # => NameError: uninitialized constant Integer 
     34  #   i.subclasses                 # => ["Bignum", "Fixnum"] 
     35  #   Fixnum.superclass            # => Integer 
    1936  def remove_class(*klasses) 
    2037    klasses.flatten.each do |klass| 
  • trunk/activesupport/lib/active_support/core_ext/date_time/conversions.rb

    r9161 r9226  
    4646        end 
    4747 
    48         # Returns the utc_offset as an +HH:MM formatted string. Examples: 
     48        # Returns the +utc_offset+ as an +HH:MM formatted string. Examples: 
    4949        # 
    5050        #   datetime = DateTime.civil(2000, 1, 1, 0, 0, 0, Rational(-6, 24)) 
  • trunk/activesupport/lib/active_support/core_ext/date/calculations.rb

    r9093 r9226  
    1717 
    1818        module ClassMethods 
    19           # Finds yesterday's date, in the format similar to: Mon, 17 Mar 2008 
     19          # Returns a new Date representing the date 1 day ago (i.e. yesterday's date). 
    2020          def yesterday 
    2121            ::Date.today.yesterday 
    2222          end 
    2323           
    24           # Finds tommorrow's date, in the format similar to: Tue, 18 Mar 2008 
     24          # Returns a new Date representing the date 1 day after today (i.e. tomorrow's date). 
    2525          def tomorrow 
    2626            ::Date.today.tomorrow 
  • trunk/activesupport/lib/active_support/core_ext/integer/even_odd.rb

    r9093 r9226  
    44      # For checking if a fixnum is even or odd. 
    55      # 
    6       # Examples: 
    7       # 
    86      #   1.even? # => false 
    97      #   1.odd?  # => true 
    108      #   2.even? # => true 
    11       #   2.odd? # => false 
     9      #   2.odd? # => false 
    1210      module EvenOdd 
    1311        def multiple_of?(number) 
  • trunk/activesupport/lib/active_support/core_ext/integer/inflections.rb

    r9093 r9226  
    77        # Ordinalize turns a number into an ordinal string used to denote the 
    88        # position in an ordered sequence such as 1st, 2nd, 3rd, 4th. 
    9         # 
    10         # Examples: 
    119        # 
    1210        #   1.ordinalize    # => "1st" 
  • trunk/activesupport/lib/active_support/core_ext/object/instance_variables.rb

    r9093 r9226  
    3838  end 
    3939 
    40   # Copies the instance variables of +object+ into self
     40  # Copies the instance variables of +object+ into +self+
    4141  # 
    4242  # Instance variable names in the +exclude+ array are ignored. If +object+ 
  • trunk/activesupport/lib/active_support/core_ext/string/unicode.rb

    r9093 r9226  
    1111          # 
    1212          #   name = 'Claus MÃŒller' 
    13           #   name.reverse #=> "rell??M sualC" 
    14           #   name.length #=> 13 
     13          #   name.reverse #=> "rell??M sualC" 
     14          #   name.length   #=> 13 
    1515          # 
    16           #   name.chars.reverse.to_s #=> "rellÃŒM sualC" 
    17           #   name.chars.length #=> 12 
     16          #   name.chars.reverse.to_s   #=> "rellÃŒM sualC" 
     17          #   name.chars.length         #=> 12 
    1818          #    
    1919          # 
  • trunk/activesupport/lib/active_support/core_ext/time/conversions.rb

    r8699 r9226  
    2121        end 
    2222 
    23         # Convert to a formatted string. See DATE_FORMATS for builtin formats. 
     23        # Converts to a formatted string. See DATE_FORMATS for builtin formats. 
    2424        # 
    2525        # This method is aliased to <tt>to_s</tt>. 
    2626        # 
    27         # ==== Examples: 
    2827        #   time = Time.now                     # => Thu Jan 18 06:10:17 CST 2007 
    2928        # 
     
    3736        #   time.to_formatted_s(:rfc822)        # => "Thu, 18 Jan 2007 06:10:17 -0600" 
    3837        # 
    39         # == Adding your own time formats to to_formatted_s 
     38        # == Adding your own time formats to +to_formatted_s+ 
    4039        # You can add your own formats to the Time::DATE_FORMATS hash. 
    4140        # Use the format name as the hash key and either a strftime string 
     
    5049        end 
    5150         
    52         # Returns the utc_offset as an +HH:MM formatted string. Examples: 
     51        # Returns the UTC offset as an +HH:MM formatted string. 
    5352        # 
    5453        #   Time.local(2000).formatted_offset         # => "-06:00" 
     
    5857        end 
    5958 
    60         # Convert a Time object to a Date, dropping hour, minute, and second precision. 
     59        # Converts a Time object to a Date, dropping hour, minute, and second precision. 
    6160        # 
    62         # ==== Examples 
    63         #   my_time = Time.now 
    64         #   # => Mon Nov 12 22:59:51 -0500 2007 
     61        #   my_time = Time.now  # => Mon Nov 12 22:59:51 -0500 2007 
     62        #   my_time.to_date     #=> Mon, 12 Nov 2007 
    6563        # 
    66         #   my_time.to_date 
    67         #   #=> Mon, 12 Nov 2007 
    68         # 
    69         #   your_time = Time.parse("1/13/2009 1:13:03 P.M.") 
    70         #   # => Tue Jan 13 13:13:03 -0500 2009 
    71         # 
    72         #   your_time.to_date 
    73         #   # => Tue, 13 Jan 2009 
     64        #   your_time = Time.parse("1/13/2009 1:13:03 P.M.")  # => Tue Jan 13 13:13:03 -0500 2009 
     65        #   your_time.to_date                                 # => Tue, 13 Jan 2009 
    7466        def to_date 
    7567          ::Date.new(year, month, day) 
     
    8476        # Converts a Time instance to a Ruby DateTime instance, preserving UTC offset. 
    8577        # 
    86         # ==== Examples 
    87         #   my_time = Time.now 
    88         #   # => Mon Nov 12 23:04:21 -0500 2007 
     78        #   my_time = Time.now    # => Mon Nov 12 23:04:21 -0500 2007 
     79        #   my_time.to_datetime   # => Mon, 12 Nov 2007 23:04:21 -0500 
    8980        # 
    90         #   my_time.to_datetime 
    91         #   # => Mon, 12 Nov 2007 23:04:21 -0500 
    92         # 
    93         #   your_time = Time.parse("1/13/2009 1:13:03 P.M.") 
    94         #   # => Tue Jan 13 13:13:03 -0500 2009 
    95         # 
    96         #   your_time.to_datetime 
    97         #   # => Tue, 13 Jan 2009 13:13:03 -0500 
     81        #   your_time = Time.parse("1/13/2009 1:13:03 P.M.")  # => Tue Jan 13 13:13:03 -0500 2009 
     82        #   your_time.to_datetime                             # => Tue, 13 Jan 2009 13:13:03 -0500 
    9883        def to_datetime 
    9984          ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400)) 
  • trunk/activesupport/lib/active_support/core_ext/time/zones.rb

    r9107 r9226  
    1818          # Sets a global default time zone, separate from the system time zone in ENV['TZ'].  
    1919          # Accepts either a Rails TimeZone object, a string that identifies a  
    20           # Rails TimeZone object (e.g., "Central Time (US & Canada)"), or a TZInfo::Timezone object 
     20          # Rails TimeZone object (e.g., "Central Time (US & Canada)"), or a TZInfo::Timezone object. 
    2121          # 
    22           # Any Time or DateTime object can use this default time zone, via #in_time_zone. 
    23           # Example: 
     22          # Any Time or DateTime object can use this default time zone, via <tt>in_time_zone</tt>. 
    2423          # 
    2524          #   Time.zone = 'Hawaii'          # => 'Hawaii' 
  • trunk/activesupport/lib/active_support/whiny_nil.rb

    r9093 r9226  
    1 # Extensions to nil which allow for more helpful error messages for 
    2 # people who are new to rails. 
     1# Extensions to +nil+ which allow for more helpful error messages for people who 
     2# are new to Rails. 
    33# 
    4 # The aim is to ensure that when users pass nil to methods where that isn't 
    5 # appropriate, instead of NoMethodError and the name of some method used 
    6 # by the framework users will see a message explaining what type of object 
    7 # was expected. 
    8  
     4# Ruby raises NoMethodError if you invoke a method on an object that does not 
     5# respond to it: 
     6
     7#   $ ruby -e nil.destroy 
     8#   -e:1: undefined method `destroy' for nil:NilClass (NoMethodError) 
     9
     10# With these extensions, if the method belongs to the public interface of the 
     11# classes in NilClass::WHINERS the error message suggests which could be the 
     12# actual intended class: 
     13
     14#   $ script/runner nil.destroy  
     15#   ... 
     16#   You might have expected an instance of ActiveRecord::Base. 
     17#   ... 
     18
     19# NilClass#id exists in Ruby 1.8 (though it is deprecated). Since +id+ is a fundamental 
     20# method of Active Record models NilClass#id is redefined as well to raise a RuntimeError 
     21# and warn the user. She probably wanted a model database identifier and the 4 
     22# returned by the original method could result in obscure bugs. 
     23
     24# The flag <tt>config.whiny_nils</tt> determines whether this feature is enabled. 
     25# By default it is on in development and test modes, and it is off in production 
     26# mode. 
    927class NilClass 
    1028  WHINERS = [::Array] 
     
    1937  end 
    2038 
    21   # Raises a RuntimeError when you attempt to call id on nil or a nil object
     39  # Raises a RuntimeError when you attempt to call +id+ on +nil+
    2240  def id 
    2341    raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller 
     
    2947    end 
    3048 
    31     # Raises a NoMethodError when you attempt to call a method on nil, or a nil object
     49    # Raises a NoMethodError when you attempt to call a method on +nil+
    3250    def raise_nil_warning_for(class_name = nil, selector = nil, with_caller = nil) 
    3351      message = "You have a nil object when you didn't expect it!"