Skip to content

Commit

Permalink
extract property_names
Browse files Browse the repository at this point in the history
  • Loading branch information
akzhan committed Sep 8, 2013
1 parent d03aa55 commit 62a97e3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/reg_api2/entity/entity_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ class EntityBase
"taguri" # from YAML mixin
].freeze

# All r/w properties interpreted as symbol hash.
# @return [Hash] properties as hash.
def to_hash
h = {}
# Gets instance property names
# @return [Array(String)]
def property_names
methods = self.class.public_instance_methods(false).map(&:to_s)
methods.select do |n|
true &&
!SKIPPED_MEMBERS.detect { |n3| n3 == n } &&
n =~ /^[^=\?!]+$/ &&
methods.detect { |n2| "#{n}=" == n2 } &&
true
end.each do |n|
end
end

# All r/w properties interpreted as symbol hash.
# @return [Hash] properties as hash.
def to_hash
h = {}
property_names.each do |n|
v = self.send n.to_sym
h[n.to_sym] = v unless v.nil?
end
Expand Down

0 comments on commit 62a97e3

Please sign in to comment.