如何发出“尚未实施”的信号?

时间:2023-02-01 10:02:09

In the initial drafting of a new gem I need to leave some method implementations empty ( to be implemented in the next )

在最初起草一个新的gem时,我需要保留一些方法实现为空(下一个要实现)

Therefore, I would like to signal a "not implemented yet" exception

因此,我想提出一个“尚未实现”的异常

I'm wondering if there is a best practice or standard conventions specific to the Ruby language to code this kind of placeholder / exception.

我想知道是否有一种Ruby语言特有的最佳实践或标准约定来编码这种占位符/异常。

i.e: something like:

我。艾凡:类似:

5 个解决方案

#1


15  

You should raise NotImplementedError

你应该提高NotImplementedError

raise NotImplementedError

ruby-doc

ruby-doc

#2


4  

You may use the todonotes-gem

你可以使用托多诺斯-宝石

There is a documentation with some examples.

有一个文档和一些示例。

It doesn't implement an exception, but a logging mechanism and a possibility for temporary solutions.

它没有实现异常,而是实现了日志机制和临时解决方案的可能性。

#3


2  

Looks like the original answer, which suggested raising NotImplementedError, was removed. I'll take a crack at it: write documentation.

看起来原始的答案被删除了,它建议增加NotImplementedError。我将尝试一下:编写文档。

Don't add code that's just a placeholder. You wouldn't want folks coding against that API so don't even give them a chance (yourself included). Instead, document the road map you are currently planning on in the class and/or README. Then be open to it changing. Odds are by the time you get around to solving whatever problem is in the road map you'll have new thoughts on what is the appropriate solution. I think this is the right course of action in any language/framework, but I think Ruby in particular encourages us to not write code that you don't plan on having executed.

不要添加只是占位符的代码。您不会希望人们针对该API进行编码,因此甚至不给他们机会(包括您自己)。相反,在课程和/或自述中记录您当前计划的路线图。然后对它的变化保持开放的心态。当你解决任何问题的时候,你就会有新的想法,找到合适的解决方案。我认为这在任何语言/框架中都是正确的做法,但我认为Ruby特别鼓励我们不要编写您不打算执行的代码。

#4


-6  

Do not mention the unimplemented methods in the documents, or mention that they are not implemented yet. That is all.

不要在文档中提到未实现的方法,或者提到它们还没有实现。这是所有。

#5


-22  

Ruby will raise a NoMethodError for you anyway, when calling a non-existing method. That should be good enough for most cases.

无论如何,在调用不存在的方法时,Ruby都会为您提供一个NoMethodError。这对大多数情况来说都足够了。

#1


15  

You should raise NotImplementedError

你应该提高NotImplementedError

raise NotImplementedError

ruby-doc

ruby-doc

#2


4  

You may use the todonotes-gem

你可以使用托多诺斯-宝石

There is a documentation with some examples.

有一个文档和一些示例。

It doesn't implement an exception, but a logging mechanism and a possibility for temporary solutions.

它没有实现异常,而是实现了日志机制和临时解决方案的可能性。

#3


2  

Looks like the original answer, which suggested raising NotImplementedError, was removed. I'll take a crack at it: write documentation.

看起来原始的答案被删除了,它建议增加NotImplementedError。我将尝试一下:编写文档。

Don't add code that's just a placeholder. You wouldn't want folks coding against that API so don't even give them a chance (yourself included). Instead, document the road map you are currently planning on in the class and/or README. Then be open to it changing. Odds are by the time you get around to solving whatever problem is in the road map you'll have new thoughts on what is the appropriate solution. I think this is the right course of action in any language/framework, but I think Ruby in particular encourages us to not write code that you don't plan on having executed.

不要添加只是占位符的代码。您不会希望人们针对该API进行编码,因此甚至不给他们机会(包括您自己)。相反,在课程和/或自述中记录您当前计划的路线图。然后对它的变化保持开放的心态。当你解决任何问题的时候,你就会有新的想法,找到合适的解决方案。我认为这在任何语言/框架中都是正确的做法,但我认为Ruby特别鼓励我们不要编写您不打算执行的代码。

#4


-6  

Do not mention the unimplemented methods in the documents, or mention that they are not implemented yet. That is all.

不要在文档中提到未实现的方法,或者提到它们还没有实现。这是所有。

#5


-22  

Ruby will raise a NoMethodError for you anyway, when calling a non-existing method. That should be good enough for most cases.

无论如何,在调用不存在的方法时,Ruby都会为您提供一个NoMethodError。这对大多数情况来说都足够了。