<commit_before>module Module

  # Overwrite the existing useless implementation
  def define_method(name, &block)
    raise  if block.nil?

    signature = Konjure::objc_parameter_signature(block)
    objc_define_method(name, :object, signature, &block)
  end

  def objc_define_method(name, *types, &block)
    return_type, *parameter_types = Konjure::encode_objc_types(types)
    return_type ||= '@'
    parameter_types.join('')

    signature = "#{return_type}@:#{parameter_types}"
    class_replaceMethod(self, name.to_sym, block, signature.UTF8String)

    block
  end

end

module Konjure

  def self.encode_objc_types(types)
    types.flatten.map do |type|
      TYPE_SHORTCUTS[type] || type
    end
  end

  def self.objc_parameter_signature(block)
    '@' * block.arity.abs
  end

  TYPE_SHORTCUTS = {
    bool:       'B',
    boolean:    'B',
    char:       'c',
    class:      '#',
    double:     'd',
    float:      'f',
    id:         '@',
    int:        'i',
    long:       'l',
    long_long:  'q',
    object:     '@',
    pointer:    '^',
    sel:        ':',
    selector:   ':',
    short:      's',
    string:     '*',
    uchar:      'C',
    uint:       'I',
    ulong:      'L',
    ulong_long: 'Q',
    ushort:     'S',
  }

end
<commit_msg>Fix raise call when no block provided to define_method<commit_after>module Module

  # Overwrite the existing useless implementation
  def define_method(name, &block)
    raise ArgumentError, 'Block required' if block.nil?

    signature = Konjure::objc_parameter_signature(block)
    objc_define_method(name, :object, signature, &block)
  end

  def objc_define_method(name, *types, &block)
    return_type, *parameter_types = Konjure::encode_objc_types(types)
    return_type ||= '@'
    parameter_types.join('')

    signature = "#{return_type}@:#{parameter_types}"
    class_replaceMethod(self, name.to_sym, block, signature.UTF8String)

    block
  end

end

module Konjure

  def self.encode_objc_types(types)
    types.flatten.map do |type|
      TYPE_SHORTCUTS[type] || type
    end
  end

  def self.objc_parameter_signature(block)
    '@' * block.arity.abs
  end

  TYPE_SHORTCUTS = {
    bool:       'B',
    boolean:    'B',
    char:       'c',
    class:      '#',
    double:     'd',
    float:      'f',
    id:         '@',
    int:        'i',
    long:       'l',
    long_long:  'q',
    object:     '@',
    pointer:    '^',
    sel:        ':',
    selector:   ':',
    short:      's',
    string:     '*',
    uchar:      'C',
    uint:       'I',
    ulong:      'L',
    ulong_long: 'Q',
    ushort:     'S',
  }

end

{'fraction_non_alphanumeric': 0.1371275783040489, 'fraction_numerical': 0.0007639419404125286, 'mean_word_length': 2.3363057324840764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2617821', 'n_tokens_mistral': 949, 'n_tokens_neox': 926, 'n_words': 191}