Repository: NREL/OpenStudio (language: python)

Issue:
Embedded ruby 3.2.2 in CLI is missing "RUBY_DESCRIPTION" global constant
Issue overview
--------------

Missing RUBY_DESCRIPTION constant in ruby 3.2.2.

Caught while testing openstudio-ee-gem, with a VERY cryptic message:

```
NameError: uninitialized constant Git::Lib::RUBY_DESCRIPTION
```

This is because git 1.12.0 (which is quite old too, 1.19.1 is out, and there's a 2.0.0-pre too, probably should update @DavidGoldwasser ) uses it https://github.com/ruby-git/ruby-git/blob/ea79dadf07e65896a08487af011e60336e86d3e3/lib/git/lib.rb#L1209-L1213

The same would happen with this

```
module Test
  class Lib
    def f
      puts NON_DEFINED_CONSTANT
    end
  end
end

Test::Lib.new.f()
```

```
openstudio test.rb
Error: uninitialized constant Test::Lib::NON_DEFINED_CONSTANT
```


## Current Behavior

It fails

## Expected Behavior

It should be there

## Steps to Reproduce
<!-- Provide an unambiguous set of steps to reproduce this bug. -->
<!--- Provide a link to a model that has the bug (a minimum complete and verifiable example (MCVE) is preferred) and/or code to reproduce -->
1.
2.
3.
4.

## Possible Solution

https://github.com/NREL/OpenStudio/blob/ca6043ee1660ddab352b1b39329706e026382203/ruby/engine/InitRubyEngine.cpp#L280

`Init_ruby_description` is needed. Note that it doesn't take void param anymore but a pointer to a typedefed struct...

## Details

### Environment

Some additional details about your environment for this issue (if relevant):
 - Platform (Operating system, version): All
 - Version of OpenStudio (if using an intermediate build, include SHA): 3.8.0-rc1

### Context

testing on openstudio-ee-gem

Embedded ruby 3.2.2 in CLI is missing "RUBY_DESCRIPTION" global constant
Issue overview
--------------

Missing RUBY_DESCRIPTION constant in ruby 3.2.2.

Caught while testing openstudio-ee-gem, with a VERY cryptic message:

```
NameError: uninitialized constant Git::Lib::RUBY_DESCRIPTION
```

This is because git 1.12.0 (which is quite old too, 1.19.1 is out, and there's a 2.0.0-pre too, probably should update @DavidGoldwasser ) uses it https://github.com/ruby-git/ruby-git/blob/ea79dadf07e65896a08487af011e60336e86d3e3/lib/git/lib.rb#L1209-L1213

The same would happen with this

```
module Test
  class Lib
    def f
      puts NON_DEFINED_CONSTANT
    end
  end
end

Test::Lib.new.f()
```

```
openstudio test.rb
Error: uninitialized constant Test::Lib::NON_DEFINED_CONSTANT
```


## Current Behavior

It fails

## Expected Behavior

It should be there

## Steps to Reproduce
<!-- Provide an unambiguous set of steps to reproduce this bug. -->
<!--- Provide a link to a model that has the bug (a minimum complete and verifiable example (MCVE) is preferred) and/or code to reproduce -->
1.
2.
3.
4.

## Possible Solution

https://github.com/NREL/OpenStudio/blob/ca6043ee1660ddab352b1b39329706e026382203/ruby/engine/InitRubyEngine.cpp#L280

`Init_ruby_description` is needed. Note that it doesn't take void param anymore but a pointer to a typedefed struct...

## Details

### Environment

Some additional details about your environment for this issue (if relevant):
 - Platform (Operating system, version): All
 - Version of OpenStudio (if using an intermediate build, include SHA): 3.8.0-rc1

### Context

testing on openstudio-ee-gem

Embedded ruby 3.2.2 in CLI is missing "RUBY_DESCRIPTION" global constant
Issue overview
--------------

Missing RUBY_DESCRIPTION constant in ruby 3.2.2.

Caught while testing openstudio-ee-gem, with a VERY cryptic message:

```
NameError: uninitialized constant Git::Lib::RUBY_DESCRIPTION
```

This is because git 1.12.0 (which is quite old too, 1.19.1 is out, and there's a 2.0.0-pre too, probably should update @DavidGoldwasser ) uses it https://github.com/ruby-git/ruby-git/blob/ea79dadf07e65896a08487af011e60336e86d3e3/lib/git/lib.rb#L1209-L1213

The same would happen with this

```
module Test
  class Lib
    def f
      puts NON_DEFINED_CONSTANT
    end
  end
end

Test::Lib.new.f()
```

```
openstudio test.rb
Error: uninitialized constant Test::Lib::NON_DEFINED_CONSTANT
```


## Current Behavior

It fails

## Expected Behavior

It should be there

## Steps to Reproduce
<!-- Provide an unambiguous set of steps to reproduce this bug. -->
<!--- Provide a link to a model that has the bug (a minimum complete and verifiable example (MCVE) is preferred) and/or code to reproduce -->
1.
2.
3.
4.

## Possible Solution

https://github.com/NREL/OpenStudio/blob/ca6043ee1660ddab352b1b39329706e026382203/ruby/engine/InitRubyEngine.cpp#L280

`Init_ruby_description` is needed. Note that it doesn't take void param anymore but a pointer to a typedefed struct...

## Details

### Environment

Some additional details about your environment for this issue (if relevant):
 - Platform (Operating system, version): All
 - Version of OpenStudio (if using an intermediate build, include SHA): 3.8.0-rc1

### Context

testing on openstudio-ee-gem



Discussion / hints:

Fix patch:
diff --git a/ruby/engine/InitRubyEngine.cpp b/ruby/engine/InitRubyEngine.cpp
index debca1a9787..117ed69a0f1 100644
--- a/ruby/engine/InitRubyEngine.cpp
+++ b/ruby/engine/InitRubyEngine.cpp
@@ -14,6 +14,9 @@ extern "C"
 {
   // static void Init_builtin_prelude(void);
   // void Init_builtin_gem_prelude(void);
+  struct ruby_cmdline_options;
+  typedef struct ruby_cmdline_options ruby_cmdline_options_t;
+  void Init_ruby_description(ruby_cmdline_options_t*);
 }
 
 namespace openstudio {
@@ -22,6 +25,8 @@ void RubyEngine::initRubyEngine() {
   RUBY_INIT_STACK;
   ruby_init();
 
+  Init_ruby_description(nullptr);
+
   ruby_gc_set_params();
   ruby_init_loadpath();
 
diff --git a/src/model/DesignDay.cpp b/src/model/DesignDay.cpp
index 299b33524d2..2f83b6505a2 100644
--- a/src/model/DesignDay.cpp
+++ b/src/model/DesignDay.cpp
@@ -641,13 +641,10 @@ namespace model {
     }
 
     void DesignDay_Impl::ensureNoLeapDays() {
-      boost::optional<int> month;
-      boost::optional<int> day;
-
-      month = getInt(OS_SizingPeriod_DesignDayFields::Month);
-      if (month && (month.get() == 2)) {
-        day = this->getInt(OS_SizingPeriod_DesignDayFields::DayofMonth);
-        if (day && (day.get() == 29)) {
+      boost::optional<int> month_ = getInt(OS_SizingPeriod_DesignDayFields::Month);
+      if (month_ && (*month_ == 2)) {
+        boost::optional<int> day_ = this->getInt(OS_SizingPeriod_DesignDayFields::DayofMonth);
+        if (day_ && (*day_ == 29)) {
           this->setInt(OS_SizingPeriod_DesignDayFields::DayofMonth, 28);
         }
       }


Test patch:
diff --git a/ruby/test/Constants_Test.rb b/ruby/test/Constants_Test.rb
new file mode 100644
index 00000000000..3fe1d4ba8b0
--- /dev/null
+++ b/ruby/test/Constants_Test.rb
@@ -0,0 +1,30 @@
+########################################################################################################################
+#  OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
+#  See also https://openstudio.net/license
+########################################################################################################################
+
+require 'minitest/autorun'
+
+class ConstantsTest < Minitest::Test
+
+  # Note: putting all of these tests under the same one because of the way we
+  # run the tests with the CLI (we run a CLI instance for each individual test,
+  # and it takes almost 20 seconds for each which is ridiculous)
+  def test_ruby_constants
+
+    assert_equal("3.2.2", RUBY_VERSION)
+
+    refute_empty(RUBY_DESCRIPTION)
+    assert_match(/ruby 3.2.2 \(.*\) \[.*\]/, RUBY_DESCRIPTION)
+
+    assert_equal("ruby", RUBY_ENGINE)
+
+    refute_empty(RUBY_PLATFORM)
+
+    refute_empty(RUBY_RELEASE_DATE)
+
+    refute_empty(RUBY_COPYRIGHT)
+
+  end
+
+end