How to select a group or component and get the area with ruby code?

It says this because that is the last thing that happened, meaning that area_total is the name of a method that was just defined.

The web-based Ruby Console is misleading. It loads the code and does not actually run any methods unless you call them.

To get the area, you must call the method named selected_area().

Along with the above snippet … here is context menu item that you can right-click on the selection …

UI.add_context_menu_handler do |popup|
  if !Sketchup.active_model.selection.empty?
    popup.add_item("Area selected...") {
      area = selected_area()
      UI.messagebox("Area selected: #{Sketchup::format_area(area)}")
    }
  end
end

I created a pinned set of Ruby learning resources in this category: