What's the meaning of "<<"

 # File activerecord/lib/active_record/validations.rb, line 327

327: def validate(*methods, &block)
328: methods << block if block_given?
329: write_inheritable_set(:validate, methods)
330: end

there is an example:
class Comment < ActiveRecord::Base
validate do |comment|
comment.must_be_friends
end

def must_be_friends
  errors.add_to_base("Must be friends to leave a comment") unless

commenter.friend_of?(commentee)
end
end
Understand how this matter?

On 26 Mar 2008, at 09:13, Cai Guichao wrote:

# File activerecord/lib/active_record/validations.rb, line 327

327: def validate(*methods, &block)
328: methods << block if block_given?
329: write_inheritable_set(:validate, methods)
330: end

On an array << is just append. Why do you ask ?

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs