Hiding Entities

I just tried applying the .hidden method to an array of entities, which it did not like. I’m assuming that I will need to loop through the array and hide each entity but I wanted to check here first if possibly I was missing something.

When you get a MethodMissingError exception, that is what it means. That the receiver object does not respond to or have such a method.

1 Like

This seems to do the trick:

new_face1 = @entities1.add_face pt1, pt2, pt3, pt4
new_face1.pushpull -@Wallhgt
		
	if @Lineoption_db == "YES"
		face_edges1 = new_face1.edges
		for edgei in face_edges1 do
			edgei.hidden = true
		end
	end

Ruby 2

new_face1 = @entities1.add_face pt1, pt2, pt3, pt4
new_face1.pushpull -@Wallhgt

  if @Lineoption_db == "YES"
    hide_all = proc {|ent| ent.hidden= true }
    new_face1.edges.each(&hide_all)
  end

REF: File: calling_methods.rdoc [Ruby 2.2.4]

1 Like

Off topic, but instead of passing around strings containing “YES” you can check the string directly and then pass around a Boolean value. This makes the code easier to work with as Strings aren’t usually used this way and it is easy to mistake 2lineoption_db for a boolean.

1 Like

… and String comparison is slow in Ruby.

true and false can be saved as settings and restored on startup.
Then your reference is pointing direct at one of the boolean objects, and there is no need to call the == method which also takes time, no need for the interpreter to create a new “YES” string from the literal to pass as the argument.
Your code is simply …

if @Lineoption_db
  # code
end

… or if hide_all was already a method or proc reference in scope …

new_face1.edges.each(&hide_all) if @Lineoption_db
1 Like

The various options are coming directly from the HTML so it seems just as easy to check the string rather than take an additional step to convert to a boolean and then check the boolean. Either way you still have to check the string so the efficiency is no better.

The difference matters only if you are testing the value in a loop. If you only test once in a while you won’t be able to detect any impact, but in a loop the inefficiency of the string comparison will make a big impact.

Agreed.

I will go back through my code and check on how often I do these string comparisons, if its being looped then, yes, it makes sense to switch to the boolean operators.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.