如何在ruby中打印Fixnum类的所有方法

时间:2017-07-31 10:37:24

标签: ruby class methods

我想在ruby中打印Fixnum类的所有方法。当我输入Fixnum.methods时,它会提供我不理解的输出类型。

[:allocate, :superclass, :<=>, :module_exec, :class_exec, :<=, :>=, :==, :===, :include?, :included_modules, :ancestors, :name, :public_instance_methods, :instance_methods, :private_instance_methods, :protected_instance_methods

4 个答案:

答案 0 :(得分:2)

您可能想要实例方法:

Fixnum.instance_methods

过滤来自Object

的内容
Fixnum.instance_methods - Object.instance_methods

答案 1 :(得分:1)

考虑安装_htmlHelper.PartialAsync

<!-- Views/Shared/TagHelpers/TagsEditor --> @model ModelExpression <input asp-for="@Model" class="form-control" data-provider="tagseditor" /> [HtmlTargetElement("tags-editor", Attributes = "for", TagStructure = TagStructure.WithoutEndTag)] public class TagsEditorTagHelper : TagHelper { private HtmlHelper _htmlHelper; private HtmlEncoder _htmlEncoder; public TagsEditorTagHelper(IHtmlHelper htmlHelper, HtmlEncoder htmlEncoder) { _htmlHelper = htmlHelper as HtmlHelper; _htmlEncoder = htmlEncoder; } [HtmlAttributeName("for")] public ModelExpression For { get; set; } [ViewContext] public ViewContext ViewContext { set => _htmlHelper.Contextualize(value); } public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { output.TagName = null; //exception thrown here: var partial = await _htmlHelper.PartialAsync("TagHelpers/TagsEditor", For); var writer = new StringWriter(); partial.WriteTo(writer, _htmlEncoder); output.Content.SetHtmlContent(writer.ToString()); } } 的更好版本,允许浏览类和对象“就像它们是文件夹一样”。参见例如

pry

答案 2 :(得分:0)

这是一个ruby数组,方法名称用符号表示(另一个ruby东西)。你可以做到

Fixnum.methods.each { |method| puts method }

来自ruby 2.4.0及更高版本

Integer.methods.each { |method| puts method }

答案 3 :(得分:0)

您获得的输出是一个方法名称数组作为符号。所以,如果你想打印它们就像这样:

Fixnum.methods.each { |method| puts method }