Class: Natto::MeCabStruct

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/natto/struct.rb

Overview

MeCabStruct is a general base class for FFI::Struct objects in the Natto module. Please refer to mecab.h in the source code distribution.

Direct Known Subclasses

DictionaryInfo, MeCabNode

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(attr_name) ⇒ Object

Provides accessor methods for the members of the MeCab struct.

Parameters:

  • attr_name (String)

    attribute name

Returns:

  • member values for the MeCab struct

Raises:

  • (NoMethodError)

    if attr_name is not a member of this MeCab struct



16
17
18
19
20
21
# File 'lib/natto/struct.rb', line 16

def method_missing(attr_name)
  member_sym = attr_name.id2name.to_sym
  self[member_sym]
rescue ArgumentError # `member_sym` field doesn't exist.
  raise(NoMethodError.new("undefined method '#{attr_name}' for #{self}"))
end