Ruby objects without 'to_s' [closed] - ruby

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Are there any objects in ruby that don't respond to to_s?
The question isn't meant to ask whether it is possible to create one, which I know can be done by undef_method. Feel free to explain details, including caveats of undefining.

The BasicObject class does not define a to_s method, so any instance of that class would not have a to_s method.

We should never specialize a subclass, since the subclass would not attend to the parent expectation anymore, have a look in the Liskov Substitution Principle.

Related

What are the new JVM arguments introduces in Java8? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Very basic but can any one tell me what are the new JVM arguments introduces in Java8?
I am not able to find any concrete list over net.
I know about a few of them only (that I got to use), like:
-parameters (for named parameters)
Since the addition of meta-space, these were added (used only a few of them)
InitialBootClassLoaderMetaspaceSize
MaxMetaspaceExpansion
MaxMetaspaceFreeRatio
MaxMetaspaceSize
MetaspaceSize
MinMetaspaceExpansion
MinMetaspaceFreeRatio
UseLargePagesInMetaspace
And one about lambda usage:
-Djdk.internal.lambda.dumpProxyClasses = /Some/Path
I only vaguely know about these two:
MinHeapFreeRatio
MaxHeapFreeRatio
I am absolutely sure there are many more...

String replace to method [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I need to replace a localized string to localized method.
From:
"social_1.localized()"
To:
"social_1".localized()
What is the best way to do?
May be this:
"social_1.localized()".gsub(".localized()","").localized()
or
my_string, my_method = "social_1.localized()".split('.')
my_method = my_method.gsub!("()",'').to_sym
my_string.send(my_method)
#uri-agassi (see comment) is right. using send this way may be a security risk. especially if it comes from user input (i.e. from the params object). you could think about to whitelist callable methods:
if [:upcase, :downcase, :capitalize].include?(my_method)
my_string.send(my_method)
end
Or at least ask the object, that it knowns the method to call:
my_string.send(my_method) if my_string.respond_to?(my_method)

When creating a DSL in Ruby, is it possible to create an alternate version of `def`? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
It is possible to call define_method directly or from within a method call that accepts a block. But is it possible to create a new method or keyword that performs manipulation on code and then declares it into a method, but has the same syntax as the built-in def?
No. You can define a method, but you cannot define a keyword. Whatever method you define on the Module class, you cannot pass a method body to it without the do keyword, unlike with def.

What module do the class `Hash`, `Array`, `File` belong to? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Simple question:
What module do the class Hash, Array, File belong to ?
Would you just say that they are part of the ruby core?
They are instances of the Class module (class).
Classes don't "belong to modules". They are just objects like any other object. If you are asking about the constants Hash, Array, File, etc., those belong to the Object class. All constants that are not explicitly defined in some specific module belong to Object.
The simple answer to the simple question is Yes they are part of Ruby Core
Yes. Hash, Array, File they all belongs to core.

Undefined method for method in another class [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Sorry for the potentially stupid question, I'm quite new to Ruby, and object orientation all together, however, I get
dby.rb:30:in <class:DBYConfig>': undefined methodparse' for DBY::DBYConfig:Class (NoMethodError)
from dby.rb:8:in <module:DBY>'
from dby.rb:6:in'
Here is the code:
https://gist.github.com/zackp30/6374d13ee1f88948c833
#parse is an instance method of the class DBYConfig, that's why you got error. Change DBY::DBYConfig.parse to DBY::DBYConfig.new.parse. Same explanation go to the method #init_conf, as with #parse . Thus change DBY::DBYConfig.init_conf, to DBY::DBYConfig.new.init_conf.

Resources