Class: WWW::Delicious::Element
Overview
Abstract structure
Represent the most basic structure all Struc(s) must inherith from.
Class Method Summary (collapse)
-
+ (Object) from_rexml(element, options)
Creates and returns new instance from a REXML element.
Instance Method Summary (collapse)
-
- (Element) initialize(attrs = {}) {|_self| ... }
constructor
Initializes a new instance and populate attributes from attrs.
Constructor Details
- (Element) initialize(attrs = {}) {|_self| ... }
Initializes a new instance and populate attributes from attrs.
class User < Element
attr_accessor :first_name
attr_accessor :last_name
end
User.new
User.new(:first_name => 'foo')
User.new(:first_name => 'John', :last_name => 'Doe')
You can even use a block. The following statements are equals:
User.new(:first_name => 'John', :last_name => 'Doe')
User.new do |user|
user.first_name => 'John'
user.last_name => 'Doe'
end
Warning. In order to set an attribute a valid attribute writer must be available, otherwise this method will raise an exception.
52 53 54 55 56 |
# File 'lib/www/delicious/element.rb', line 52 def initialize(attrs = {}, &block) attrs.each { |key, value| self.send("#{key}=".to_sym, value) } yield self if block_given? self end |
Class Method Details
+ (Object) from_rexml(element, options)
Creates and returns new instance from a REXML element.
64 65 66 |
# File 'lib/www/delicious/element.rb', line 64 def from_rexml(element, ) raise NotImplementedError end |