Saturday, 15 September 2012

ruby - Using `defined?` at one-level expansion -


Define method ? Returns the result for the syllabic expression given as an argument, for example, the result of

  is defined? Foo   

Is sensitive that the foo is really any defined variable / method, it does not matter if the foo is a string Is defined as a valid (existing) expression:

  foo = "array"   

or not:

  foo = "nonExistingConstant"   

What is it possible to define ? The logic given is a level extension? That is, for foo = "Array" , it should be returned to "continuous" and foo = "NonExistingConstant" , it should be sent to < Code> zero . if so, how?

Since you only have to check constants:

  ['array' , 'Nonexistent class']. Do each. Name | What is called Object.const_defined? (Name) end # & gt; & Gt; True # & gt; & Gt; False    

No comments:

Post a Comment