[Ruby] 0. play with it a little bit

class BlogEntry
  attr_acces­sor  :title, :fulltext, :mood
end

entry = BlogEntry.new
entry.title = "Today Mt. Hood was stolen!"
entry.time = Time.now
entry.mood = :sick //another mothod
entry.fulltext = "BABABABA..."

//See what you have done
entry

//
class BlogEntry
  def initialize( title, mood, fulltext )
    @time = Time.now
    @title, @mood, @fulltext = title, mood, fulltext
  end
end

entry = BlogEntry.new("I left my Hoodie on the desk", "Today is interesting",
"I love you! Alice")

/*
Accessors are variables attached to an object which can be used outside the object. (entry.time = Time.now)
Instance variables are the same variables you're using for accessors when inside the object. Like in a method definition. (@time = Time.now)
*/

blog.each do |entry|
..    h1 "Zhen­tian"
..    h2 entry.title
..    p entry.fulltext
..    end


/**
Once you have Ruby installed, you can use Interactive Ruby by running irb on your system's command line utility.
*/

 

posted @ 2014-09-10 01:38  Zhentiw  阅读(144)  评论(0)    收藏  举报