Module: Yapra::Plugin::FeedItemOperator

Included in:
Base
Defined in:
lib/yapra/plugin/feed_item_operator.rb

Constant Summary collapse

LOCAL_VAL_RE =
/[a-z_][0-9A-Za-z_]/

Instance Method Summary collapse

Instance Method Details

#set_attribute_to(item, k, value) ⇒ Object

Raises:

  • (NameError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/yapra/plugin/feed_item_operator.rb', line 6

def set_attribute_to item, k, value
  raise NameError unless LOCAL_VAL_RE =~ k
  unless item.respond_to?("#{k}=")
    item.instance_eval %Q{
      def #{k}
        @#{k}
      end
      def #{k}= v
        @#{k} = v
      end
    }, __FILE__, __LINE__
    
  end
  item.__send__("#{k}=", value)
end