Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

This function will get all the "setters" for a specific class where the class_name argument is a string, e.g. BuildingStory. The same can be done for getters, resetters, autosizers, etc.

# return an array of all set methods for specific class_name string
def self.get_setters(class_name)

  array = []

  instance_methods = OpenStudio::Model.const_get(class_name).instance_methods
  instance_methods.each do |instance_method|
    array << instance_method if instance_method.to_s.start_with? 'set'
  end
  array.pop(12) # remove the last 12 elements, which are general setters

  return array

end

This function will get all the "setters" for a specific class where the class_name argument is a string, class, e.g. BuildingStory. The same can be done for getters, resetters, autosizers, etc.

# return an array of all set methods for specific class_name string
def self.get_setters(class_name)

  array = []

  instance_methods = OpenStudio::Model.const_get(class_name).instance_methods
  instance_methods.each do |instance_method|
    array << instance_method if instance_method.to_s.start_with? 'set'
  end
  array.pop(12) # remove the last 12 elements, which are general setters

  return array

end

This function will get all the "setters" for a specific class, e.g. BuildingStory. The same can be done for getters, resetters, autosizers, etc.

# return an array of all set methods for specific class_name string
def self.get_setters(class_name)
get_setters(class_name)

  array = []

  instance_methods = OpenStudio::Model.const_get(class_name).instance_methods
  instance_methods.each do |instance_method|
    array << instance_method if instance_method.to_s.start_with? 'set'
  end
  array.pop(12) # remove the last 12 elements, which are general setters

  return array

end

This function will get all the "setters" for a specific class, e.g. BuildingStory. BuildingStory. The same can be done for getters, resetters, autosizers, etc.

# return an array of all set methods for specific class_name string
def get_setters(class_name)

  array = []

  instance_methods = OpenStudio::Model.const_get(class_name).instance_methods
  instance_methods.each do |instance_method|
    array << instance_method if instance_method.to_s.start_with? 'set'
  end
  array.pop(12) # remove the last 12 elements, which are general setters

  return array

end

This function will get all the "setters" for a specific class, e.g. BuildingStory. BuildingStory, without the need for instantiation. The same can be done for getters, resetters, autosizers, etc.etc. and could be adapted to simply get all the instance_methods as @Denis Bourgeois suggested.

# return an array of all set methods for specific class_name string
def get_setters(class_name)

  array = []

  instance_methods = OpenStudio::Model.const_get(class_name).instance_methods
  instance_methods.each do |instance_method|
    array << instance_method if instance_method.to_s.start_with? 'set'
  end
  array.pop(12) # remove the last 12 elements, which are general setters

  return array

end