Cyclomatic complexity for method is too high How do i refactor my code to fix the lint error i am getting?

  def value=(val)
    if val
      if [:char].include?(@type) &amp;&amp; val.length &gt;= args[:limit] &amp;&amp; val == 'true'
        val = 'Y'
      elsif [:char].include?(@type) &amp;&amp; val.length &gt;= args[:limit] &amp;&amp; val == 'false'
        val = 'N'
      elsif [:bit].include?(@type) &amp;&amp; val.length &gt;= args[:limit] &amp;&amp; val == 'true'
        val = 1
      elsif [:bit].include?(@type) &amp;&amp; val.length &gt;= args[:limit] &amp;&amp; val == 'false'
        val = 0
      elsif [:varchar, :char, :nvarchar].include?(@type) &amp;&amp; @args[:limit]
        unless val.length &lt;= args[:limit]
          msg = "The length of #{@name} exceeds the max limit #{@args[:limit]}"
          raise Programmability::BadRequestError.new(nil, msg)
        end
      elsif [:numeric].include?(@type) &amp;&amp; @args[:precision] &amp;&amp; @args[:scale]
        valid_numeric?(val, @args[:precision], @args[:scale])
      elsif [:datetime].include?(@type)
        valid_date?(val)
      end
    end
    @value = val
  end
[x].include?(y) is the most roundabout way I've ever seen of saying x == y. 
You're repeating val.length &gt;= args[:limit] for almost every. single. case.
Why is there an instance variable called @args? That smells like you didn't bother to actually handle things in the constructor, and instead just store everything for later. Also, why are you using @args directly, when it seems you also have a reader/accessor method, args? Using the accessor is better, though you can use either - just don't mix them.
Why isn't there code after the calls to valid_numeric? and valid_date?? The prefix valid_... and the ? in the names indicate that those methods (should!) return boolean values. But if they do, you're ignoring it - which doesn't make sense. So it smells like those methods don't so much validate anything, but actually set @value to something. No thanks.
You're overwriting the argument val, which isn't pretty. Make a new local variable instead, or write to @value directly.
What if val is just false? Not the word, but the boolean? In that case all the logic will be skipped, and you'll go straight to @val = false. It doesn't matter whatever @type is, or whatever args[:limit] is. I think you want your if to check for val.nil? specifically.


It seems like what you really want is 4-6 different classes to handle different datatypes. Whatever you're trying to do, you're doing too much of it in one method and one class.