Sketchup.load
-
If we are not using .rbs, is there any reason to use Sketchup.load rather than just load?
-
I see this note on the Google SketchUp forum:
*[pre:jdmy8csy]"Sketchup.load behaves just like Sketchup.require.
I just wanted to make note in case anyone was expecting Sketchup.load
to behave the same as its Ruby equivalent."[/pre:jdmy8csy]*Could that be true?
-
The current docs for Sketchup#require:
http://www.sketchup.com/intl/en/developer/docs/ourdoc/sketchup?csw=1#requireThis is an alias of the Sketchup.load method.
Although because of the behavior, I suspect Sketchup#load is the alias for Sketchup#require, and the docs are incorrect.
-
Either way it is a confusion.
We use "require" when we only want to load something once - and are prepared to exit and restart SketchUp if we want to change something an load it again.
But, especially when debugging our code, we want to use 'load' to reload a ruby which we are debugging without having to exit and restart SketchUp. (Perhaps we should reload it, but it is awfully convenient to be able to reload a ruby and test it on the fly)
Because we incorrectly assumed that Sketchup.load() and load() were identical, except for the processing of .rbs files, SketchUp.load() occasionally slipped into something which would have worked with load.
Ah, but C'est la Vie - it is too late now for SketchUp to make load and require operated differently, and more in keeping with Ruby load and require. So we'll just have to be more careful to use just load().
-
You could test using the unscrambled file, then load would work as expected.
-
Yea, it's an annoying deviance that Sketchup::load acts like Sketchup::require.
For my personal projects I got reload code for when testing RBS files where I remove the file from the $LOADED_FEATURES list.
-
@al hart said:
Ah, but C'est la Vie - it is too late now for SketchUp to make load and require operated differently, and more in keeping with Ruby load and require.
I totally disagree and always will.
If it is wrong, fix it make it correct, at the first best opportunity.
With this release using Ruby 2.0, was the perfect time to fix it so that developers could check their code, and update it at the same time they fixed other things that needed fixing for Ruby 2.x.
-
@jim said:
You could test using the unscrambled file, then load would work as expected.
I don't think Sketchup.load ever works as expected.
I expected it to load the .rb or .rbs, even if I had already loaded it before.
What it does is quietly "not load" it if it has been loaded already.
-
@dan rathbun said:
I totally disagree and always will.
If it is wrong, fix it make it correct, at the first best opportunity.
With this release using Ruby 2.0, was the perfect time to fix it so that developers could check their code, and update it at the same time they fixed other things that needed fixing for Ruby 2.x.
You are right Dan. This release would have been a great time to fix this, and we could all have looked through our code for calls to Sketchup.load() to anticipate problems.
Also, if Sketchup.load() always loaded things, rather than just the first time, if would almost never create a real problem. So they should just fix it now.
(It would "create a problem", if some one was changing .rb files on the fly, and then loading them with Sketchup.load and expecting that the would only load if they had not already been loaded. I suspect that no one is actually doing this. We do have code which creates ruby files on the fly, and then loads them - but we expect them to actually get loaded. [We wrote these as part of an early CAD System to SketchUp importer which created a ruby file of the geometry of the CAD System, and then loaded to ruby file to import the geometry.])
-
@tt_su said:
Yea, it's an annoying deviance that Sketchup::load acts like Sketchup::require.
For my personal projects I got reload code for when testing RBS files where I remove the file from the $LOADED_FEATURES list.
$LOADED_FEATURES - Aha! I didn't know about that. I guess you learn something ever day.
Advertisement